Kaggle competition: Cassava Leaf Disease Classification
<SOS> metric: CategorizationAccuracy Kaggle data source: cassava-leaf-disease-classification<compute_test_metric>
import numpy as np
import pandas as pd
import os
from fastai.vision.all import *
print('RMSLE:', np.sqrt(metrics.mean_squared_log_error(np.expm1(y_test), np.expm1(pred))))<compute_train_metric>
cassavaPath = '.. /input/cassava-leaf-disease-classification/'
cassavaOutputPath = './'
cassavaModelPath = '.. /input/cassavleafdiseaseclassificationpretrained/'
df = pd.read_csv(cassavaPath+'train.csv')
 df['label'] = df['label'].astype(str)
 df.head()
gbm = GradientBoostingRegressor(n_estimators=2000,alpha=0.01)
 gbm.fit(X_train,y_train)
 preds = gbm.predict(X_test)
 print('RMSLE:', np.sqrt(metrics.mean_squared_log_error(np.expm1(y_test), np.expm1(preds))))<compute_test_metric>
df['label'].value_counts()
algo_gbm = gbm.predict(X_test)
 algo_rf = rfr.predict(X_test)
 algo_mean =np.expm1(algo_gbm)*0.9 + np.expm1(algo_rf)*0.1
print('RMSLE:', np.sqrt(metrics.mean_squared_log_error(np.expm1(y_test), algo_mean)) )<predict_on_test>
dls = dblock.dataloaders(df )
algo_gbm_tst = gbm.predict(test)
 algo_rf_tst = rfr.predict(test)
 algo_mean_tst =np.expm1(algo_gbm_tst)*0.9 + np.expm1(algo_rf_tst)*0.1<prepare_output>
dls.show_batch(nrows=3, ncols=3 )
submission = pd.DataFrame({'datetime':df_test['datetime'],'count':algo_mean_tst})
 submission.head()<save_to_csv>
submission.to_csv('Submission.csv',index=False )<load_from_csv>
train=pd.read_csv("/kaggle/input/bike-sharing-demand/train.csv")
 train.head(10 )<load_from_csv>
learn = load_learner(cassavaModelPath+'CassavaDiseaseModelResnet34.pkl')
 learn.export(cassavaOutputPath+'CassavaDiseaseModelResnet34.pkl')
 learn = load_learner(cassavaOutputPath+'CassavaDiseaseModelResnet34.pkl' )
test=pd.read_csv("/kaggle/input/bike-sharing-demand/test.csv")
 test.head(10 )<data_type_conversions>
print('Computing predictions...')
 test_files = get_image_files(cassavaPath+'test_images')
 predictions_ResultArray = [None for tempX in range(len(test_files)) ]
predictions_InputArray = [None for tempX in range(len(test_files)) ]
for test_idx in range(0,len(test_files)) :
predictions = learn.predict(test_files[test_idx])
 head, tail = os.path.split(test_files[test_idx])
 predictions_ResultArray[test_idx] = int(predictions[0])
 predictions_InputArray[test_idx] = tail
np.savetxt(cassavaOutputPath+'submission.csv', np.rec.fromarrays([predictions_InputArray, predictions_ResultArray]), fmt=['%s', '%d'], delimiter=',', header='image_id,label', comments='')
 !head submission.csv
<feature_engineering><EOS> 
df_sample_submission = pd.read_csv('.. /input/cassava-leaf-disease-classification/sample_submission.csv')
 df_exact_submission = pd.read_csv(cassavaOutputPath+'submission.csv')
 print(df_sample_submission.compare(df_exact_submission))
print(df_sample_submission.equals(df_exact_submission))