Kaggle competition: Aerial Cactus Identification
model.predict(dataset.iloc[old_man_nan_fare_idx].drop(['Survived'], axis=1))<predict_on_test>
df = pd.DataFrame.from_csv('.. /input/aerial-cactus-identification/train.csv', index_col=None)
 df.head()
dataset.loc[train_len:, 'Survived'] = model.predict(dataset[train_len:].drop(['Survived'], axis=1))<sort_values>
makedirs('/tmp/.torch/models/' )
survived_corr = pd.DataFrame(dataset.corr() ['Survived'].drop('Survived'))
survived_corr_most = survived_corr[ 
(survived_corr['Survived'] > 0.1)|(survived_corr['Survived'] < -0.1)]\ 
.sort_values(['Survived'], ascending=True )<feature_engineering>
test_data = ImageList.from_folder('.. /input/aerial-cactus-identification/test/test')
 trfm = 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)
 data =(ImageList.from_df(df, path='.. /input/aerial-cactus-identification/train/train')
.split_by_rand_pct(0.1)
.label_from_df() 
.add_test(test_data)
.transform(trfm, size=128)
.databunch(path='.', bs=64, device= torch.device('cuda:0')) 
.normalize(imagenet_stats)
 )
traindf = pd.read_csv('.. /input/titanic/train.csv' ).set_index('PassengerId')
 testdf = pd.read_csv('.. /input/titanic/test.csv' ).set_index('PassengerId')
 df = pd.concat([traindf, testdf], axis=0, sort=False)
 df['Title'] = df.Name.str.split(',' ).str[1].str.split('.' ).str[0].str.strip()
df['IsWomanOrBoy'] =(( df.Title == 'Master')|(df.Sex == 'female'))
df['LastName'] = df.Name.str.split(',' ).str[0]
family = df.groupby(df.LastName ).Survived
df['WomanOrBoyCount'] = family.transform(lambda s: s[df.IsWomanOrBoy].fillna(0 ).count())
 df['WomanOrBoyCount'] = df.mask(df.IsWomanOrBoy, df.WomanOrBoyCount - 1, axis=0)
 df['FamilySurvivedCount'] = family.transform(lambda s: s[df.IsWomanOrBoy].fillna(0 ).sum())
 df['FamilySurvivedCount'] = df.mask(df.IsWomanOrBoy, df.FamilySurvivedCount - df.Survived.fillna(0), axis=0)
 df['WomanOrBoySurvived'] = df.FamilySurvivedCount / df.WomanOrBoyCount.replace(0, np.nan)
 df.WomanOrBoyCount = df.WomanOrBoyCount.replace(np.nan, 0)
 df['Alone'] =(df.WomanOrBoyCount == 0)
 train_y = df.Survived.loc[traindf.index]
df2 = pd.concat([df.WomanOrBoySurvived.fillna(0), df.Alone, df.Sex.replace({'female': 0, 'male': 1})], axis=1)
 test_x = df2.loc[testdf.index]
y_pred_top3 =(((test_x.WomanOrBoySurvived <= 0.238)&(test_x.Sex < 0.5)&(test_x.Alone > 0.5)) | \ 
(( test_x.WomanOrBoySurvived > 0.238)& \
~(( test_x.WomanOrBoySurvived > 0.55)&(test_x.WomanOrBoySurvived <= 0.633)))).astype(int)
 pd.DataFrame({'Survived': y_pred_top3}, \
index=testdf.index ).reset_index().to_csv('survived_top3.csv', index=False)
 print('Mean =', y_pred_top3.mean() , ' Std =', y_pred_top3.std() )<set_options>
data.path = pathlib.Path('.')
 learn = cnn_learner(data, models.resnet18, metrics=accuracy)
 learn.lr_find()
print(__doc__)
 warnings.filterwarnings("ignore")
 np.random.seed(0 )<feature_engineering>
learn.fit_one_cycle(5, 1e-02 )
df['Title'] = df['Title'].replace('Ms','Miss')
 df['Title'] = df['Title'].replace('Mlle','Miss')
 df['Title'] = df['Title'].replace('Mme','Mrs' )<feature_engineering>
preds = learn.get_preds(ds_type=DatasetType.Test)
 preds = [x[1] for x in preds[0].tolist() ]
preds
df['Embarked'] = df['Embarked'].fillna('S' )<data_type_conversions>
pred_df = []
for item in zip(data.test_ds.items, preds):
pred_df.append([item[0].stem + '.jpg', item[1]] )
med_fare = df.groupby(['Pclass', 'Parch', 'SibSp'] ).Fare.median() [3][0][0]
df['Fare'] = df['Fare'].fillna(med_fare )<feature_engineering>
pred_df = pd.DataFrame(pred_df, columns=['id', 'has_cactus'] )
<feature_engineering><EOS> 
pred_df.to_csv('submission.csv', index=False )