Kaggle competition: Plant Pathology 2020 - FGVC7
<SOS> metric: MCAUC Kaggle data source: plant-pathology-2020-fgvc7<train_model>
import numpy as np
import pandas as pd
import os
from scipy.stats import entropy
params = {
'num_leaves': 2048,
'learning_rate': 0.01,
'n_estimators': 1000,
'min_data_in_leaf': 400,
'max_bin': 1000,
'random_state': 42,
'objective' : 'regression',
'metric': 'mae'
}
model = lgb.LGBMRegressor(**params, verbose=2, n_jobs=4, silent=False)
 model.fit(X_train, y_train, eval_metric= 'mae' )<predict_on_test>
sub1 = pd.read_csv('.. /input/average-efficientnet/submission.csv')
 sub2 = pd.read_csv('.. /input/classification-densenet201-efficientnetb7/submission.csv')
 sub3 = pd.read_csv('.. /input/tf-zoo-models-on-tpu/submission.csv')
 sub4 = pd.read_csv('.. /input/fork-of-plant-2020-tpu-915e9c/submission.csv')
 sub = pd.read_csv('.. /input/plant-pathology-2020-fgvc7/sample_submission.csv' )
prediction = model.predict(X_test )<feature_engineering>
ent1 = entropy(sub1.loc[:,'healthy' : ], base=2, axis = 1)
 ent2 = entropy(sub2.loc[:,'healthy' : ], base=2, axis = 1)
 ent3 = entropy(sub3.loc[:,'healthy' : ], base=2, axis = 1)
 ent4 = entropy(sub4.loc[:,'healthy' : ], base=2, axis = 1)
 entropies = np.array([ent1, ent2, ent3, ent4] ).transpose()
entropies.shape
selected = np.argmin(entropies, axis = 1 )
for i in range(len(test_df_raw)) :
winPlacePerc = prediction[i]
maxPlace = int(test_df_raw.iloc[i]['maxPlace'])
 if maxPlace == 0:
winPlacePerc = 0.0
elif maxPlace == 1:
winPlacePerc = 1.0
else:
gap = 1.0 /(maxPlace - 1)
 winPlacePerc = round(winPlacePerc / gap)* gap
if winPlacePerc < 0: winPlacePerc = 0.0
if winPlacePerc > 1: winPlacePerc = 1.0
prediction[i] = winPlacePerc<save_to_csv>
result_df = test_df_raw.copy()
result_df['winPlacePerc'] = prediction
result_df.head()
result_df.to_csv('submission.csv', columns=['Id', 'winPlacePerc'], index=False )<load_from_csv>
submission_size = len(selected)
 for i in range(submission_size):
if selected[i] ==0:
sub.loc[i, 'healthy' : ] = sub1.loc[i, 'healthy' :]
elif selected[i] ==1:
sub.loc[i, 'healthy' : ] = sub2.loc[i, 'healthy' :]
elif selected[i] == 2:
sub.loc[i, 'healthy' : ] = sub3.loc[i, 'healthy' :]
elif selected[i] == 3:
sub.loc[i, 'healthy' : ] = sub4.loc[i, 'healthy' :]
train = pd.read_csv(".. /input/train_V2.csv")
 test = pd.read_csv(".. /input/test_V2.csv")
 display(train.head())
 display(test.head() )<count_unique_values>
sub.to_csv('submission.csv', index=False )
display('matchId category count={}'.format(train['matchId'].nunique()))
display('groupId category count={}'.format(train['groupId'].nunique()))
display('matchType category count={}'.format(train['matchType'].nunique()))
matchId = train['matchId'].value_counts()
groupId = train['groupId'].value_counts()
matchType = train['matchType'].value_counts()<count_missing_values>
sub.to_csv('submission.csv', index=False )