Kaggle competition: Aerial Cactus Identification
<SOS> metric: AUC Kaggle data source: aerial-cactus-identification<set_options>
start = time.time()
init_notebook_mode(connected=True )<set_options>
data_folder = Path(".. /input" )
%matplotlib inline<load_from_csv>
train_df = pd.read_csv(data_folder/'train.csv')
 test_df = pd.read_csv(data_folder/'sample_submission.csv' )
df_train = pd.read_csv('.. /input/titanic/train.csv')
 df_test = pd.read_csv('.. /input/titanic/test.csv')
 df_sub = pd.read_csv('.. /input/titanic/gender_submission.csv' )<count_values>
test_data = ImageList.from_df(test_df, path=data_folder/'test', folder='test' )
df_train.dtypes.value_counts()<count_values>
train_imgs =(ImageList.from_df(train_df, path=data_folder/'train', folder='train')
.split_by_rand_pct(0.1)
.label_from_df() 
.add_test(test_data)
.transform(get_transforms(flip_vert=True), size=128)
.databunch(path='.', bs=96)
.normalize(imagenet_stats)
)
df_test.dtypes.value_counts()<count_values>
learner = cnn_learner(train_imgs, models.densenet161 )
df_train["Survived"].value_counts()<count_missing_values>
lr = 3e-2
missing_rate_train =(df_train.isna().sum() /df_train.shape[0] ).sort_values()
nb_missing = df_train.isna().sum().sort_values()
print(f'{"Variable" :-<40} {"missing_rate_train":-<30} {"Number of missing values":-<30}')
 for n in range(len(missing_rate_train)) :
print(f'{missing_rate_train.index[n] :-<30} {missing_rate_train[n]:-<30} {nb_missing[n]:-<30}' )<count_missing_values>
learner.fit_one_cycle(6, max_lr = slice(lr))
missing_rate_test =(df_test.isna().sum() /df_test.shape[0] ).sort_values()
nb_missing = df_test.isna().sum().sort_values()
print(f'{"Variable" :-<30} {"missing_rate_train":-<30} {"Number of missing values":-<30}')
 for n in range(len(missing_rate_test)) :
print(f'{missing_rate_test.index[n] :-<30} {missing_rate_test[n]:-<30} {nb_missing[n]:-<30}' )<feature_engineering>
preds,_ = learner.get_preds(ds_type=DatasetType.Test )
def TransfromAge(df_aux):
GroupAge = ['inf-10', '10-18', '18-35', '35-65', 'sup-65']
cond1 =(df_aux["Age"].isnull())&(df_aux["title"]=="Master")
 df_aux.loc[cond1, 'Age'] = calcul_median(df_aux,"Master")
 cond2 =(df_aux["Age"].isnull())&(df_aux["title"]=="Miss")
 df_aux.loc[cond2, 'Age'] = calcul_median(df_aux,"Miss")
 cond3 =(df_aux["Age"].isnull())&(df_aux["title"]=="Mrs")
 df_aux.loc[cond3, 'Age'] = calcul_median(df_aux,"Mrs")
 cond4 =(df_aux["Age"].isnull())&(df_aux["title"]=="Mr")
 df_aux.loc[cond4, 'Age'] = calcul_median(df_aux,"Mr")
 cond5 =(df_aux["Age"].isnull())&(df_aux["title"]=="officier/capitaine")
 df_aux.loc[cond5, 'Age'] = calcul_median(df_aux,"officier/capitaine")
 cond6 =(df_aux["Age"].isnull())&(df_aux["title"]=="royale")
 df_aux.loc[cond6, 'Age'] = calcul_median(df_aux,"royale")
 bins = [0, 10, 18, 35, 65, np.inf]
GroupAge = ['inf-10', '10-18', '18-35', '35-65', 'sup-65']
df_aux['GroupAge'] = pd.cut(df_aux['Age'], bins, labels=GroupAge)
 return df_aux
def calcul_median(df_aux,ch):
return df_aux[df_aux["title"]==ch].Age.dropna().median()<filter>
test_df.has_cactus = preds.numpy() [:, 0]
<categorify><EOS> 
test_df.to_csv('submission.csv', index=False )