Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<load_pretrained>
pd.plotting.register_matplotlib_converters()
%matplotlib inline
%matplotlib inline
%matplotlib inline
plt.style.use('seaborn-whitegrid')
 warnings.filterwarnings('ignore' )
best_model2 = best_model_with_fixed_embeddings.copy('best_model_low', 'best_optimizer_low')
 best_model2.load(net, optimizer)
 for g in optimizer.param_groups:
g['lr'] = 0.00003
train_network(net, optimizer,criterion,train_loader,val_loader,10, 3,best_model2)
 best_model2.load(net, optimizer )<load_pretrained>
train=pd.read_csv("/kaggle/input/titanic/train.csv")
 X_test=pd.read_csv("/kaggle/input/titanic/test.csv")
 X_test.copy()
train.info()
best_model2.load(net, optimizer )<train_model>
from fastai.tabular import *
train_network(net, optimizer,criterion,train_loader,val_loader,10, 3,best_model)
 best_model.load(net, optimizer )<load_pretrained>
procs = [FillMissing, Categorify, Normalize]
dep_var = 'Survived'
cat_names = ['Sex', 'Cabin', 'Embarked']
cont_names = ['PassengerId', 'Pclass', 'Age', 'SibSp', 'Parch', 'SibSp']
X=train[cont_names]
X=train[cat_names]
best_model.load(net, optimizer )<predict_on_test>
data =(TabularList.from_df(train, procs=procs, cont_names=cont_names, cat_names=cat_names)
.split_by_idx(valid_idx=range(int(len(train)*0.9),len(train)))
.label_from_df(cols=dep_var)
.add_test(TabularList.from_df(X_test, cat_names=cat_names, cont_names=cont_names, procs=procs)) 
.databunch())
 print(data.train_ds.cont_names)
 print(data.train_ds.cat_names )
def predict_loader(network, loader):
network.eval()
all_predictions = []
with torch.no_grad() :
for X,_ in tqdm_notebook(loader, total=len(loader)) :
X = X.cuda()
out = network(X ).view(-1)
 out = torch.sigmoid(out)
 all_predictions.extend(out.tolist())
 return np.array(all_predictions )<predict_on_test>
learn = tabular_learner(data, layers=[1000,500], metrics=accuracy, wd=0.1 )
network_pred = predict_loader(net, val_loader )<set_options>
learn.fit_one_cycle(5, 2.5e-2 )
print(net.embedding.weight.requires_grad )<find_best_params>
learn.fit_one_cycle(5, 2.6e-9 )
prc = metrics.precision_recall_curve(val_labels.values, network_pred, pos_label=1 )<import_modules>
learn.save('stage-1' )
import matplotlib.pyplot as plt<compute_test_metric>
preds, _ = learn.get_preds(ds_type=DatasetType.Test)
 pred_prob, pred_class = preds.max(1 )
exact_predictions = np.round(network_pred)
 print(metrics.classification_report(val_labels.values, exact_predictions))<compute_test_metric>
submission = pd.DataFrame({'PassengerId': X_test.PassengerId, 'Survived':pred_class} )
<statistical_test><EOS> 
submission.to_csv('my_submission.csv', index=False )