Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<load_from_csv>
import numpy as np
import pandas as pd
sub1 = pd.read_csv('.. /input/blending-power-0-9754/sub.csv')
 sub2 = pd.read_csv('.. /input/tta-power-densenet169/submission_tta_64.csv')
 sub3 = pd.read_csv('.. /input/you-really-need-attention-pytorch/sub_tta.csv' )<feature_engineering>
sample_submission = pd.read_csv('.. /input/titanic/gender_submission.csv')
 test = pd.read_csv('.. /input/titanic/test.csv')
 train = pd.read_csv('.. /input/titanic/train.csv' )
sub1.label =(sub1.label + sub2.label + sub3.label)/ 3<save_to_csv>
train['Survived'].value_counts(dropna=False )
sub1.to_csv('ensemble.csv', index=False )<import_modules>
kf = model_selection.StratifiedKFold(n_splits=5)
 x = list(kf.split(train, train['Survived'].values))
print('fast.ai version:{}'.format(fastai.__version__))<load_from_csv>
[len(i)for i in x]
show_doc(ImageDataBunch.from_csv )<load_from_csv>
all_data = train.append(test, sort=True ).fillna({'Survived': -1})
 len(train), len(test), len(all_data )
param_transforms = {
'flip_vert':True,
'max_rotate':90,
'max_zoom':1,
'max_warp':None,
'max_lighting':None,
}
params = {'path': Path('.. /input/histopathologic-cancer-detection'),
'csv_labels':'train_labels.csv',
'ds_tfms':get_transforms(**param_transforms),
'suffix':'.tif',
'folder':'train',
'test':'test',
'size':32,
'bs':128,
'num_workers':0,
}
data = ImageDataBunch.from_csv(**params ).normalize(imagenet_stats)
 data<define_variables>
def count_na(series):
return series.isna().sum()
agg_funcs =('nunique', count_na)
 dv = 'Survived'
summary_df = all_data.aggregate(agg_funcs, dropna=False ).transpose()
for dv_val in all_data[dv].unique() :
dv_val_data =(
 all_data 
.loc[lambda df: df[dv] == dv_val] 
.aggregate(agg_funcs, dropna=False ).transpose() 
)
 summary_df[pd.MultiIndex.from_product([[f'{dv}_{dv_val}'], dv_val_data.columns])] = dv_val_data
summary_df['dtypes'] = all_data.dtypes
summary_df['cardinality'] = np.where(summary_df['nunique'] > 20, 'many', 'few')
 summary_df = summary_df.sort_values(['dtypes', 'nunique'] ).drop(dv)
 summary_df
data.show_batch(rows=3 )<choose_model_class>
for _, row in summary_df[['dtypes', 'cardinality']].drop_duplicates().iterrows() :
print(
 f"{row['dtypes']} {row['cardinality']}:",
summary_df.loc[
lambda df:(df['dtypes'] == row['dtypes'])&(df['cardinality'] == row['cardinality'])
 ].index.tolist() ,
)