Kaggle competition: Plant Pathology 2020 - FGVC7
<save_to_csv><EOS> 
import pandas as pd
<SOS> metric: MCAUC Kaggle data source: plant-pathology-2020-fgvc7<set_options>
import pandas as pd
%matplotlib inline
plt.rcParams['axes.labelsize'] = 14
plt.rcParams['xtick.labelsize'] = 12
plt.rcParams['ytick.labelsize'] = 12
sns.set()
warnings.filterwarnings('ignore')
 gc.enable()<create_dataframe>
sub1 = pd.read_csv(
 '.. /input\
/classification-densenet201-efficientnetb7\
/submission.csv' 
)
 sub2 = pd.read_csv(
 '.. /input\
/tf-zoo-models-on-tpu\
/submission.csv' 
)
 sub3 = pd.read_csv(
 '.. /input\
/fork-of-plant-2020-tpu-915e9c\
/submission.csv'
)
def draw_missing_data_table(df):
total = df.isnull().sum().sort_values(ascending=False)
 percent =(df.isnull().sum() /df.isnull().count() ).sort_values(ascending=False)
 missing_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
 return missing_data<define_variables>
sub = pd.read_csv(
 '.. /input\
/plant-pathology-2020-fgvc7\
/sample_submission.csv'
)
path_train = '.. /input/train_V2.csv'
path_test = '.. /input/test_V2.csv'<load_from_csv>
a = 0.00
b = 0.10
c = 1.00
train_df_raw = pd.read_csv(path_train)
 train_df_raw.head()<count_missing_values>
sub.healthy = sub1.healthy*a \
+ sub2.healthy*b \
+ sub3.healthy*c
draw_missing_data_table(train_df_raw )<count_values>
sub.multiple_diseases = sub1.multiple_diseases * a \
+ sub2.multiple_diseases * b \
+ sub3.multiple_diseases * c
train_df_raw['matchType'].value_counts()<drop_column>
sub.rust = sub1.rust*a \
+ sub2.rust*b \
+ sub3.rust*c
def preprocess_data(df, with_categorical=False):
processed_df = df.drop(['Id', 'rankPoints'], axis=1)
 print('-'*5 + ' handling matchType column ' + '-'*5)
 new_matchType_cols = list()
if with_categorical:
for mtype in processed_df['matchType']:
if mtype in ['squad', 'squad-fpp', 'normal-squad-fpp', 'normal-squad', 'flarefpp', 'flaretpp']:
new_matchType_cols.append([3])
 elif mtype in ['solo', 'solo-fpp', 'normal-solo-fpp', 'normal-solo']:
new_matchType_cols.append([1])
 else:
new_matchType_cols.append([2])
 match_df = pd.DataFrame(new_matchType_cols, columns=['matchType'], index=processed_df.index)
 else:
for mtype in processed_df['matchType']:
if mtype in ['squad', 'squad-fpp', 'normal-squad-fpp', 'normal-squad', 'flarefpp', 'flaretpp']:
new_matchType_cols.append([1, 0, 0])
 elif mtype in ['solo', 'solo-fpp', 'normal-solo-fpp', 'normal-solo']:
new_matchType_cols.append([0, 0, 1])
 else:
new_matchType_cols.append([0, 1, 0])
 match_df = pd.DataFrame(new_matchType_cols, columns=['squad','duo', 'solo'], index=processed_df.index)
 processed_df = processed_df.drop(['matchType'], axis=1)
 print('-'*5 + ' create matchSize column ' + '-'*5)
 match_size = processed_df.groupby(['matchId'] ).size().reset_index(name='matchSize')
 processed_df = processed_df.merge(match_size, how='left', on=['matchId'])
 print('-'*5 + ' create teamSize column ' + '-'*5)
 processed_df['combinedId'] = processed_df['matchId'] + processed_df['groupId']
group_size = processed_df.groupby(['combinedId'] ).size().reset_index(name='teamSize')
 processed_df = processed_df.merge(group_size, how='left', on=['combinedId'])
 print('-'*5 + ' create totalDistance column ' + '-'*5)
 processed_df['totalDistance'] = processed_df['rideDistance'] + processed_df['walkDistance'] + processed_df['swimDistance']
processed_df = processed_df.drop(['combinedId', 'matchId', 'groupId'], axis=1)
 processed_df = processed_df.join(match_df)
 processed_df = processed_df.drop(['teamKills', 'vehicleDestroys', 'roadKills', 'swimDistance', 'headshotKills', 'solo', 'duo', 'squad'], 1)
 return processed_df<prepare_x_and_y>
sub.scab = sub1.scab*a \
+ sub2.scab*b \
+ sub3.scab*c
train_df = preprocess_data(train_df_raw.dropna())
 X_train = train_df.drop('winPlacePerc', 1)
 y_train = train_df['winPlacePerc']
sc = StandardScaler()
X_train = pd.DataFrame(sc.fit_transform(X_train.values), index=X_train.index, columns=X_train.columns)
 X_train.head()<load_from_csv>
sub.to_csv('submission.csv', index=False )
<create_dataframe><EOS> 
sub.to_csv('submission.csv', index=False )