Kaggle competition: Aerial Cactus Identification
<SOS> metric: AUC Kaggle data source: aerial-cactus-identification<count_values>
%reload_ext autoreload
%autoreload 2
%matplotlib inline
df['Survived'].value_counts()<concatenate>
from fastai.vision import *
from fastai import *
from fastai.metrics import error_rate
import pandas as pd
import torch
final = pd.concat([df,tf],axis = 0)
 final.drop(['Survived'],axis = 1,inplace = True )<feature_engineering>
path =".. /input/"
train_df=pd.read_csv(path+"train.csv")
 test_df=pd.read_csv(path+"sample_submission.csv" )
index_NaN_age = list(final["Age"][final["Age"].isnull() ].index)
 for i in index_NaN_age :
age_med = final["Age"].median()
age_pred = final["Age"][(( final['SibSp'] == final.iloc[i]["SibSp"])&(final['Parch'] == final.iloc[i]["Parch"])&(final['Pclass'] == final.iloc[i]["Pclass"])) ].median()
if not np.isnan(age_pred):
final['Age'].iloc[i] = age_pred
else :
final['Age'].iloc[i] = age_med<count_missing_values>
bs = 128
data = ImageDataBunch.from_csv(path=path, folder='train/train', csv_labels='train.csv', ds_tfms=get_transforms() , size=32, bs=bs ).normalize(imagenet_stats )
final['Age'].isnull().sum()<data_type_conversions>
data.show_batch(rows=3, figsize=(7,6))
final['Age'].fillna(final['Age'].median() ,inplace = True)
<count_missing_values>
data.classes, data.c, len(data.train_ds), len(data.valid_ds )
final['Fare'].isnull().sum()<feature_engineering>
learn = cnn_learner(data, models.densenet161, metrics=error_rate, model_dir="/tmp/model/" )
final["Fare"] = final["Fare"].fillna(final["Fare"].median())
<feature_engineering>
learn.fit_one_cycle(6 )
final["Fare"] = final["Fare"].map(lambda n: np.log(n)if n > 0 else 0)
<feature_engineering>
learn.fit_one_cycle(5, max_lr=slice(3e-5,3e-4))
new = final['Name'].str.split('.', n=1, expand = True)
 final['First'] = new[0]
final['Last'] = new[1]
new1 = final['First'].str.split(',', n=1, expand = True)
 final['Last Name'] = new1[0]
final['Title'] = new1[1]
new2 = final['Title'].str.split('', n=1, expand = True )<count_values>
interp = ClassificationInterpretation.from_learner(learn )
final['Title'].value_counts()<drop_column>
a,b,c=learn.predict(open_image(".. /input/test/test/"+"000940378805c44108d287872b2f04ce.jpg"))
print(c)
 print(c[1].numpy() )
final.drop(['First','Last','Name','Last Name'],axis = 1,inplace = True )<categorify>
def pred(name):
a,b,c=learn.predict(open_image(".. /input/test/test/"+name))
return c[1].numpy()
final.replace(to_replace = [ ' Don', ' Rev', ' Dr', ' Mme',
' Major', ' Sir', ' Col', ' Capt',' Jonkheer'], value = ' Honorary(M)', inplace = True)
 final.replace(to_replace = [ ' Ms', ' Lady', ' Mlle',' the Countess', ' Dona'], value = ' Honorary(F)', inplace = True )<concatenate>
test_df["has_cactus"]=test_df["id"].apply(lambda x:pred(x))
<count_values><EOS> 
test_df.to_csv('submission.csv',index=False )