Kaggle competition: Cassava Leaf Disease Classification
<SOS> metric: CategorizationAccuracy Kaggle data source: cassava-leaf-disease-classification<train_model>
InteractiveShell.ast_node_interactivity = "all"
train = False
xgr=xgb.XGBRegressor(learning_rate =0.1, n_estimators=1000, max_depth=9,
min_child_weight=4, gamma=0.125, subsample=1, colsample_bytree=0.8)
 xgr.fit(train_df.drop(columns='count',axis=1),train_df['count'])
 y_predict=xgr.predict(test_df )<feature_engineering>
fastai.__version__
test_df['count']=np.exp(y_predict )<create_dataframe>
labels = pd.read_csv(path / 'train.csv')
 labels["image_id"] = labels["image_id"].apply(
 lambda x: f'train_images/{x}')
 labels.head()
result=pd.DataFrame()<feature_engineering>
dls = ImageDataLoaders.from_df(
 labels,
path='.. /input/cassava-leaf-disease-classification/',
bs=64,
fn_col=0,
label_col=1,
seed=42,
valid_pct=0.2,
item_tfms=RandomResizedCrop(512, min_scale=0.75, ratio=(1.,1.)),
batch_tfms=aug_transforms() ,
num_workers=0)
 dls.valid_ds.items[:3]
result['datetime']=test_df['datetime']
result['count']=test_df['count']<save_to_csv>
learn = cnn_learner(dls, resnet50, metrics=[error_rate, accuracy] ).to_native_fp16()
result.to_csv('output.csv',index=False )<load_from_csv>
if train:
learn.fine_tune(10, cbs=[MixUp(0.5)] )
train = pd.read_csv('.. /input/labeledTrainData.tsv',delimiter = '\t')
 test = pd.read_csv('.. /input/testData.tsv',delimiter = '\t')
 train.shape, test.shape<count_values>
model_name = "resnet50-fine_tune-10_resize-512"
if train:
learn.export(Path(f"{Path(os.getcwd() ).parent}/output/cassava-leaf-disease-classification/{model_name}.pkl"))
else:
learn = load_learner(Path(f"{Path(os.getcwd() ).parent}/input/cassava-modelresnet34fine-tune10pkl/{model_name}.pkl"), cpu=False)
 learn = learn.to_native_fp32()
learn
print("number of rows for sentiment 1: {}".format(len(train[train.sentiment == 1])))
 print("number of rows for sentiment 0: {}".format(len(train[train.sentiment == 0])) )<feature_engineering>
if train:
cleaner = ImageClassifierCleaner(learn)
 cleaner
train['length'] = train['review'].apply(len)
 train.head()<filter>
test_labels = pd.read_csv(path / 'sample_submission.csv')
 test_labels["image_id"] = test_labels["image_id"].apply(
 lambda x: f'test_images/{x}')
 test_labels.head()
train[train['length'] == 13708]['review'].iloc[0]<string_transform>
test_predictions = []
for i, r in test_labels.iterrows() :
test_predictions.append(int(learn.predict(f'.. /input/cassava-leaf-disease-classification/{r.image_id}')[0]))
test_predictions[0]
<feature_engineering><EOS> 
submission = pd.read_csv(path / 'sample_submission.csv')
 submission['label'] = test_predictions
submission.head()
submission.to_csv('submission.csv',index=False )