Kaggle competition: Cassava Leaf Disease Classification
<SOS> metric: CategorizationAccuracy Kaggle data source: cassava-leaf-disease-classification<init_hyperparams>
from fastai.vision.all import *
lgb_params = {
"boosting_type": "gbdt",
"colsample_bytree": 0.5,
"early_stopping_rounds": 100,
"learning_rate": 0.005,
"max_bin": 255,
"max_depth": -1,
"metric": "auc",
"n_estimators": 20000,
"n_jobs": -1,
"num_leaves": 2**9,
"objective": "binary",
"seed": SEED,
"subsample": 0.7,
"subsample_freq": 1,
"tree_learner": "serial"
}<drop_column>
path = Path('.. /input/cassava-leaf-disease-classification' )
feature_columns = list(train.columns)
 target_column = "isFraud"
columns_to_drop = ["TransactionID", "isFraud", "TransactionDT"]
for c in columns_to_drop:
feature_columns.remove(c )<prepare_x_and_y>
train_df = pd.read_csv(path/'train.csv')
 train_df = train_df[~train_df['image_id'].isin(['1562043567.jpg', '3551135685.jpg', '2252529694.jpg'])]
X, y = train[feature_columns], train[target_column]
P = test[feature_columns]<prepare_x_and_y>
def get_x(r):
return path/'train_images'/r['image_id']
def get_y(r):
return r['label']
%%time
N_SPLITS = 5
folds = KFold(n_splits=N_SPLITS, shuffle=True, random_state=SEED)
 train_preds = np.zeros(train.shape[0])
 test_preds = np.zeros(test.shape[0])
 del train, test
gc.collect()
feature_importance = pd.DataFrame()
feature_importance["Feature"] = X.columns
feature_importance["Value"] = 0
for fold_idx,(train_idx, valid_idx)in enumerate(folds.split(X, y)) :
print("Fold", fold_idx + 1)
 train_x, train_y = X.iloc[train_idx, :], y[train_idx]
valid_x, valid_y = X.iloc[valid_idx, :], y[valid_idx]
model = lgb.LGBMClassifier(**lgb_params)
 model.fit(train_x, train_y, eval_set=[(train_x, train_y),(valid_x, valid_y)], verbose=100)
 train_preds[valid_idx] = model.predict_proba(valid_x, num_iteration=model.best_iteration_)[:, 1]
test_preds += model.predict_proba(P, num_iteration=model.best_iteration_)[:, 1] / folds.n_splits
print("Fold {} AUC: {:.6f}".format(fold_idx + 1, roc_auc_score(valid_y, train_preds[valid_idx])))
 current_importance = pd.DataFrame(zip(X.columns, model.feature_importances_), columns=["Feature", "Value"])
 feature_importance = pd.concat(( feature_importance, current_importance)).groupby("Feature", as_index=False ).sum()
print("Global AUC: {:.6f}".format(roc_auc_score(y, train_preds)) )<save_to_csv>
loss_func = LabelSmoothingCrossEntropy()
submission = pd.read_csv(".. /input/ieee-fraud-detection/sample_submission.csv")
 submission[target_column] = test_preds
submission.to_csv("submission.csv", index=False )<save_to_csv>
learn = cnn_learner(dls, resnet50, metrics= [accuracy], loss_func=loss_func, opt_func=ranger, pretrained=False ).to_native_fp16()
feature_importance.sort_values("Value", ascending=False ).to_csv("feature_importance.csv", index=False )<save_to_csv>
learn.load('/kaggle/input/leaf-resnet50/model_6' )
feature_importance.sort_values("Value", ascending=False)[["Feature"]].to_csv("feature_importance_name_only.csv", index=False )<load_from_csv>
learn = learn.to_native_fp32()
start_time = time.time()
print("loading data takes about 1 minute.... ")
 train_transaction = pd.read_csv('/kaggle/input/ieee-fraud-detection/train_transaction.csv', index_col='TransactionID')
 test_transaction = pd.read_csv('/kaggle/input/ieee-fraud-detection/test_transaction.csv', index_col='TransactionID')
 train_identity = pd.read_csv('/kaggle/input/ieee-fraud-detection/train_identity.csv', index_col='TransactionID')
 test_identity = pd.read_csv('/kaggle/input/ieee-fraud-detection/test_identity.csv', index_col='TransactionID')
 print("loading successful!" )<count_values>
submission_df = pd.read_csv(path/'sample_submission.csv')
 submission_df.head()
print("train_transaction.index:
", train_transaction.index, "
")
 print("train_identity.index:
", train_identity.index, "
")
 print(train_identity.id_01.value_counts() , "
")
 print(train_identity.id_07.value_counts() , "
")
 print(train_identity.DeviceType.value_counts() , "
")
 print(train_identity.DeviceInfo.value_counts() , "
" )<rename_columns>
test_data_path = submission_df['image_id'].apply(lambda x: path/'test_images'/x)
 tst_dl = learn.dls.test_dl(test_data_path)
 predictions = learn.tta(dl = tst_dl, n=10)
 submission_df['label'] = np.argmax(predictions[0],axis=1)
 submission_df
<define_variables><EOS> 
submission_df.to_csv('submission.csv',index=False )