Kaggle competition: Aerial Cactus Identification
dummy1 = pd.get_dummies(data1['Embarked'], prefix='Embarked', drop_first=True)
 data1 = pd.concat([data1, dummy1], axis=1 )<categorify>
%matplotlib inline
dummy1 = pd.get_dummies(data_val['Embarked'], prefix='Embarked', drop_first=True)
 data_val = pd.concat([data_val, dummy1], axis=1 )<categorify>
train_df = pd.read_csv(".. /input/train.csv")
 train_df.head()
dummy1 = pd.get_dummies(data1['Pclass'], prefix='Pclass', drop_first=True)
 data1 = pd.concat([data1, dummy1], axis=1 )<categorify>
test_df = pd.read_csv(".. /input/sample_submission.csv")
 test_img = ImageList.from_df(test_df, path=".. /input", folder='test/test')
 tfms = get_transforms(do_flip=True, flip_vert=True, max_rotate=10.0, max_zoom=1.1, max_lighting=0.2, max_warp=0.2, p_affine=0.75, p_lighting=0.75 )
dummy1 = pd.get_dummies(data_val['Pclass'], prefix='Pclass', drop_first=True)
 data_val = pd.concat([data_val, dummy1], axis=1 )<categorify>
data =(ImageList.from_df(train_df,path=".. /input/train",folder="train")
.split_by_rand_pct() 
.label_from_df() 
.add_test(test_img)
.transform(tfms,size = 128)
.databunch(path='.',bs=64)
.normalize(imagenet_stats)
 )
dummy1 = pd.get_dummies(data1['Sex'], prefix='Male', drop_first=True)
 data1 = pd.concat([data1, dummy1], axis=1 )<categorify>
data.show_batch(rows=3,figsize =(5,5))
dummy1 = pd.get_dummies(data_val['Sex'], prefix='Male', drop_first=True)
 data_val = pd.concat([data_val, dummy1], axis=1 )<feature_engineering>
data.valid_ds.classes
data1['FamilySize'] = data1['SibSp'] + data1['Parch'] + 1
data1.head(2 )<feature_engineering>
model = cnn_learner(data,models.resnet152, metrics = [accuracy] )
data_val['FamilySize'] = data_val['SibSp'] + data_val['Parch'] + 1
data_val.head(2 )<define_variables>
lr = 1e-5
model.fit_one_cycle(5,lr )
PassengerId = data_val.PassengerId<rename_columns>
model.fit_one_cycle(10,max_lr=slice(1e-2,1e-4))
data1= data1.rename(columns={ 'Male_1' : 'Male'})
 data_val= data_val.rename(columns={ 'Male_1' : 'Male'} )<drop_column>
model.fit_one_cycle(10,max_lr=slice(1e-2,1e-4))
drop_column = ['PassengerId', 'Pclass', 'Name', 'Sex', 'Ticket', 'Fare', 'Embarked']
data1.drop(drop_column, axis=1, inplace = True )<split>
model.fit_one_cycle(10,max_lr=slice(1e-2,1e-4))
target = 'Survived'
y = data1[target]
x = data1.drop(columns = target)
 x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state = 42)
 y = data1["Survived"]
features = ["Age", "Male","Pclass_2", "Pclass_3","FamilySize"]
X = pd.get_dummies(data1[features])
 X_test = pd.get_dummies(x_test[features] )<train_model>
model.save('stage-1-resnet152' )
model = RandomForestClassifier(n_estimators=100, max_depth=3, random_state=1)
 model.fit(X, y)
 predictions = model.predict(X_test)
 score = accuracy_score(y_test, predictions)
 print("Score: ",score )<save_to_csv>
interpreter = ClassificationInterpretation.from_learner(model)
X_val = pd.get_dummies(data_val[features])
 predictions_test = model.predict(X_val)
 output = pd.DataFrame({'PassengerId': PassengerId, 'Survived': predictions_test})
 output.to_csv('my_submission_RFC.csv', index=False)
 print("Your submission was successfully saved!" )<set_options>
img = model.data.test_ds
img
<load_from_csv><EOS> 
preds, _ = model.get_preds(ds_type=DatasetType.Test)
 test_df.has_cactus = preds.numpy() [:,0]
test_df.to_csv('submission.csv', index=False )