Kaggle competition: Cassava Leaf Disease Classification
<SOS> metric: CategorizationAccuracy Kaggle data source: cassava-leaf-disease-classification<prepare_x_and_y>
Cassava_dir = ".. /input/cassava-leaf-disease-classification/"
dataTrain = data[pd.notnull(data['count'])]
dataTest= data[~pd.notnull(data['count'])].sort_values(by=['datetime'])
 datetimecol = dataTest['datetime']
yLabels = dataTrain['count']
yLabels_log = np.log(yLabels+1)
<drop_column>
model = keras.models.load_model('.. /input/cassava-baseline-weights/best_weights.h5' )
dropFeatures = ['casual' , 'count' , 'datetime' , 'registered' , 'date' ,
'windspeed' , 'atemp' ,'season','weather','month','year']
dataTrain = dataTrain.drop(dropFeatures,axis=1)
 dataTest = dataTest.drop(dropFeatures,axis=1 )<import_modules>
sub = pd.DataFrame(columns=['image_id','label'] )
from sklearn.model_selection import train_test_split<import_modules>
def predict_on_batch(test_list, wpath=Cassava_dir, target_size=(380,380)) :
input_batch=[]
for IMAGE_ID in test_list:
image = tf.keras.preprocessing.image.load_img(os.path.join(wpath, "test_images",IMAGE_ID),
grayscale=False,
color_mode="rgb",
target_size=target_size,
interpolation="nearest")
 input_arr = keras.preprocessing.image.img_to_array(image)
 input_batch.append(input_arr)
 return np.array(input_batch )
from sklearn.model_selection import train_test_split<split>
TEST_DIR = '.. /input/cassava-leaf-disease-classification/test_images/'
test_images = os.listdir(TEST_DIR)
 N = len(test_images)
 if N == 1:
BATCH_SIZE = 1
else:
BATCH_SIZE = 16
X_train, X_valid, y_train, y_valid = train_test_split(dataTrain,
yLabels_log, test_size=0.1, random_state=42)
<import_modules>
for batch_index in range(math.ceil(N/BATCH_SIZE)) :
if batch_index*BATCH_SIZE+BATCH_SIZE < N:
test_X = predict_on_batch(test_images[batch_index*BATCH_SIZE:batch_index*BATCH_SIZE+BATCH_SIZE])
 predictions = model.predict(test_X ).argmax(axis = 1)
 sub_batch = pd.DataFrame({'image_id':test_images[batch_index*BATCH_SIZE:batch_index*BATCH_SIZE+BATCH_SIZE],
'label':list(predictions)})
 else:
test_X = predict_on_batch(test_images[batch_index*BATCH_SIZE:])
 predictions = model.predict(test_X ).argmax(axis = 1)
 sub_batch = pd.DataFrame({'image_id':test_images[batch_index*BATCH_SIZE:],
'label':list(predictions)})
 sub = sub.append(sub_batch, ignore_index=True )
from sklearn.ensemble import RandomForestRegressor<import_modules>
sub['label'] = sub['label'].astype('int64')
 sub
<save_to_csv><EOS> 
sub.to_csv('submission.csv', index = False )