Kaggle competition: Cassava Leaf Disease Classification
<SOS> metric: CategorizationAccuracy Kaggle data source: cassava-leaf-disease-classification<feature_engineering>
!pip install.. /input/faiss-163/faiss_cpu-1.6.3-cp37-cp37m-manylinux2010_x86_64.whl
<predict_on_test>
try:
!cd.. /input; python -m cassavacodes.Cassava.retrieval.extract.run --config-file./configs/extract_r50_gq_infer.py --load-path.. /input/wwwwww/weight_epoch_13.pth --log-dir /kaggle/working/log -device 0
except:
pass
def predict_windspeed(data):
dataWind0 = data.loc[data['windspeed'] == 0]
dataWindNot0 = data.loc[data['windspeed'] != 0]
wCol = ["season", "weather", "humidity", "month", "temp", "year", "atemp"]
dataWindNot0["windspeed"] = dataWindNot0["windspeed"].astype("str")
 rfModel_wind = RandomForestClassifier()
rfModel_wind.fit(dataWindNot0[wCol], dataWindNot0["windspeed"])
 wind0Values = rfModel_wind.predict(X = dataWind0[wCol])
 predictWind0 = dataWind0
predictWindNot0 = dataWindNot0
predictWind0["windspeed"] = wind0Values
data = predictWindNot0.append(predictWind0)
 data["windspeed"] = data["windspeed"].astype("float")
 data.reset_index(inplace=True)
 data.drop('index', inplace=True, axis=1)
 return data<data_type_conversions>
np.load('/kaggle/working/features/extract_r50_gq_infer/gallery_targets.npy' )
categorical_feature_names = ["season","holiday","workingday","weather",
"dayofweek","month","year","hour"]
for var in categorical_feature_names:
train[var] = train[var].astype("category")
 test[var] = test[var].astype("category" )<define_variables>
gallery_features = np.load('.. /input/gallery/gallery_features.npy')
 gallery_targets = np.load('.. /input/gallery/gallery_targets.npy')
 query_features = np.load('/kaggle/working/features/extract_r50_gq_infer/gallery_features.npy')
 query_names = np.load('/kaggle/working/features/extract_r50_gq_infer/gallery_names.npy')
 faiss.normalize_L2(gallery_features)
 faiss.normalize_L2(query_features)
feature_names = ["season", "weather", "temp", "atemp", "humidity", "windspeed",
"year", "hour", "dayofweek", "holiday", "workingday"]
feature_names<compute_test_metric>
index = faiss.IndexFlatL2(gallery_features.shape[1])
 index.add(gallery_features)
 k=3
D, I = index.search(gallery_features, k)
 print(gallery_targets[I[-10:]])
 outliers = []
for i, indices in enumerate(I):
if gallery_targets[indices[0]] != gallery_targets[indices[1]]:
outliers.append(i)
 print(gallery_features.shape)
 gallery_features = np.delete(gallery_features , outliers, axis=0)
 gallery_targets = np.delete(gallery_targets , outliers, axis=0)
 print(gallery_features.shape )
def rmsle(predicted_values, actual_values):
predicted_values = np.array(predicted_values)
 actual_values = np.array(actual_values)
 log_predict = np.log(predicted_values + 1)
 log_actual = np.log(actual_values + 1)
 difference = log_predict - log_actual
difference = np.square(difference)
 mean_difference = difference.mean()
score = np.sqrt(mean_difference)
 return score
rmsle_scorer = make_scorer(rmsle)
 rmsle_scorer<choose_model_class>
index = faiss.IndexFlatL2(gallery_features.shape[1])
 index.add(gallery_features)
 k=1
D, I = index.search(query_features, k)
 f = open('submission.csv', 'w')
 f.write('image_id,label
')
 for fn, i in zip(query_names, I):
fn = fn.split('/')[-1]
pred = gallery_targets[i][0]
f.write(fn + ',' + str(pred)+ '
')
 f.close()
<choose_model_class><EOS> 
f = open('submission.csv', 'r')
 print(f.readlines())
 f.close()