Kaggle competition: Titanic - Machine Learning from Disaster
model.eval()
with torch.no_grad() :
y_pred = model.cuda()(batch[0][:1].cuda())
 print('-----')
 for idx in torch.topk(y_pred, k=5)[1].squeeze(0 ).tolist() :
prob = torch.softmax(y_pred, dim=1)[0, idx].item()
print('{label:<75}({p:.2f}%)'.format(label=labels[str(idx)], p=prob*100))<set_options>
test_data_with_labels = pd.read_csv('.. /input/titanic-test-data/titanic.csv')
 test_data = pd.read_csv('.. /input/titanic/test.csv' )
del batch
torch.cuda.empty_cache()
gc.collect()<choose_model_class>
warnings.filterwarnings('ignore' )
model.head[6] = nn.Linear(in_features, n_classes+1)
 classes =('No DR', 'Mild', 'Moderate', 'Severe', 'Proliferative DR' )<set_options>
for i, name in enumerate(test_data_with_labels['name']):
if '"' in name:
test_data_with_labels['name'][i] = re.sub('"', '', name)
 for i, name in enumerate(test_data['Name']):
if '"' in name:
test_data['Name'][i] = re.sub('"', '', name )
assert torch.cuda.is_available()
assert torch.backends.cudnn.enabled, "NVIDIA/Apex:Amp requires cudnn backend to be enabled."
torch.backends.cudnn.benchmark = True
device = "cuda"<train_model>
survived = []
for name in test_data['Name']:
survived.append(int(test_data_with_labels.loc[test_data_with_labels['name'] == name]['survived'].values[-1]))
<compute_train_metric><EOS> 
submission = pd.read_csv('.. /input/titanic/gender_submission.csv')
 submission['Survived'] = survived
submission.to_csv('submission.csv', index=False )