Kaggle competition: Aerial Cactus Identification
<SOS> metric: AUC Kaggle data source: aerial-cactus-identification<categorify>
%matplotlib inline
train_data = pd.get_dummies(train_data, columns = ['Pclass', 'Sex', 'Embarked'])
 train_data<prepare_x_and_y>
data_path = Path(".. /input/")
 train_df = pd.read_csv(data_path/'train.csv')
 test_df = pd.read_csv(data_path/'sample_submission.csv' )
y_train = train_data['Survived']
X_train = train_data.copy().drop(['Survived', 'Age', 'Name', 'PassengerId', 'SibSp', 'Parch', 'Ticket', 'Cabin'], axis=1)
 X_train<load_from_csv>
df1 = train_df[train_df.has_cactus==0].copy()
df2 = df1.copy()
train_df = train_df.append([df1, df2], ignore_index=True )
test_data = pd.read_csv('/kaggle/input/titanic/test.csv')
 test_data = pd.get_dummies(test_data, columns = ['Pclass', 'Sex', 'Embarked'])
 test_data<count_missing_values>
tfms = get_transforms(do_flip=True, flip_vert=True, max_rotate=20, max_lighting=0.3, max_warp=0.2, max_zoom=1.2 )
test_data.isnull().sum()<data_type_conversions>
test_images = ImageList.from_df(test_df, path=data_path/'test', folder='test')
 src =(ImageList.from_df(train_df, path=data_path/'train', folder='train')
.split_by_rand_pct(0.2)
.label_from_df() 
.add_test(test_images))
X_test = test_data.copy().drop(['Name', 'Age', 'PassengerId', 'SibSp', 'Parch', 'Ticket', 'Cabin'], axis=1)
 X_test.fillna(X_test['Fare'].mean() , inplace=True)
 X_test, X_test.isnull().sum()<train_model>
data =(src.transform(tfms,
size=128,
resize_method=ResizeMethod.PAD,
padding_mode='reflection')
.databunch(bs=256)
.normalize(imagenet_stats))
logr = LogisticRegression().fit(X_train,y_train)
 logr.predict(X_test)
 logr.score(X_train, y_train )<compute_train_metric>
data.classes, data.c
dt = DecisionTreeClassifier().fit(X_train,y_train)
 dt.predict(X_test)
 dt.score(X_train, y_train), dt.feature_importances_<compute_train_metric>
data.show_batch(rows=3, figsize=(9,9))
rf = RandomForestClassifier().fit(X_train,y_train)
 y_test = rf.predict(X_test)
 rf.score(X_train, y_train), rf.feature_importances_<save_to_csv>
learn = cnn_learner(data,
models.resnet101,pretrained=True,
metrics=[accuracy, AUROC() ],path='',model_dir='work' )
submission = pd.DataFrame({'PassengerId': np.arange(892, 892 + len(list(y_test))), 'Survived': list(y_test)})
 submission.to_csv('my_submission.csv', index=False )<load_from_csv>
learn.lr_find(stop_div=True)
 learn.recorder.plot(suggestion=True )
titanic_train = pd.read_csv('.. /input/train.csv')
 titanic_test = pd.read_csv('.. /input/test.csv' )<groupby>
lr = 3.98E-04
learn.fit_one_cycle(5, lr )
print("Age broken down by P-class")
 titanic_train.groupby('Pclass' ).mean() [['Age']]<categorify>
learn.save('step-1' )
titanic_train.loc[titanic_train.Age.isnull() , 'Age'] = titanic_train.groupby('Pclass')['Age'].transform('mean')
 titanic_test.loc[titanic_test.Age.isnull() , 'Age'] = titanic_test.groupby('Pclass')['Age'].transform('mean' )<drop_column>
learn = cnn_learner(data,
models.resnet101, pretrained=True,
metrics=[accuracy, AUROC() ],
callback_fns=[partial(SaveModelCallback)],
wd=0.1,
ps=[0.9, 0.6, 0.4],
path = '')
 learn = learn.load('.. /work/step-1' )
titanic_train = titanic_train.drop('Cabin', axis=1)
 titanic_test = titanic_test.drop('Cabin', axis=1 )<data_type_conversions>
learn.freeze_to(4)
 learn.lr_find()
learn.recorder.plot()
titanic_train['Embarked'].fillna(titanic_train['Embarked'].mode() [0], inplace=True)
 titanic_test['Fare'].fillna(titanic_test['Fare'].median() , inplace = True )<train_model>
learn.fit_one_cycle(3 )
print('Training Data Null Values')
 print(titanic_train.isnull().sum())
 print("-" * 30)
 print('Test Data Null Values')
 print(titanic_test.isnull().sum() )<groupby>
learn.fit_one_cycle(7 )
titanic_train.groupby('Survived' ).mean() [['Fare']]<filter>
probability, classification = learn.get_preds(ds_type=DatasetType.Test)
 test_df.has_cactus = probability.numpy() [:, 0]
test_df.head()
<groupby><EOS> 
test_df.to_csv("submission.csv", index=False )