Kaggle competition: Titanic - Machine Learning from Disaster
lr=1e-2/2<train_model>
train_data=pd.read_csv("/kaggle/input/titanic/train.csv")
 test_data=pd.read_csv("/kaggle/input/titanic/test.csv" )
learn.fit_one_cycle(5, slice(lr))<save_model>
train_data.isna().sum()
learn.save('stage-1-256-rn50' )<train_model>
test_data.isna().sum()
learn.fit_one_cycle(5, slice(1e-5, lr/5))<save_model>
train_data.drop(['PassengerId', 'Name', 'Ticket', 'Cabin', 'Embarked'], inplace=True, axis=1)
 test_data.drop([ 'Name', 'Ticket', 'Cabin', 'Embarked'], inplace=True, axis=1 )
learn.save('stage-2-256-rn50' )<define_variables>
train_data['Age'].fillna(24.0,inplace=True)
test =(ImageList.from_folder(path/'test-jpg-v2'))
len(test )<feature_engineering>
test_data['Age'].fillna(24.0,inplace=True )
learn_test = load_learner('/kaggle/working/', test=test, num_workers=0, bs=1)
 preds, _ = learn_test.get_preds(ds_type=DatasetType.Test)
 preds_tta, _ = learn_test.TTA(ds_type=DatasetType.Test)
<save_to_csv>
train_data.isna().sum()
thresh = 0.15
labelled_preds = [' '.join([learn_test.data.classes[i] for i,p in enumerate(pred)if p > thresh])for pred in preds]
fnames = [f.name[:-4] for f in learn_test.data.test_ds.x.items]
df = pd.DataFrame({'image_name':fnames, 'tags':labelled_preds}, columns=['image_name', 'tags'])
 df.to_csv('submission_015.csv', index=False )<save_to_csv>
test_data['Fare'].fillna(7.75,inplace=True )
thresh = 0.18
labelled_preds = [' '.join([learn_test.data.classes[i] for i,p in enumerate(pred)if p > thresh])for pred in preds]
fnames = [f.name[:-4] for f in learn_test.data.test_ds.x.items]
df = pd.DataFrame({'image_name':fnames, 'tags':labelled_preds}, columns=['image_name', 'tags'])
 df.to_csv('submission_018.csv', index=False )<save_to_csv>
test_data.isna().sum()
thresh = 0.19
labelled_preds = [' '.join([learn_test.data.classes[i] for i,p in enumerate(pred)if p > thresh])for pred in preds]
fnames = [f.name[:-4] for f in learn_test.data.test_ds.x.items]
df = pd.DataFrame({'image_name':fnames, 'tags':labelled_preds}, columns=['image_name', 'tags'])
 df.to_csv('submission_019.csv', index=False )<save_to_csv>
genderMap={
'male':0,
'female':1
}
train_data.Sex=train_data.Sex.map(genderMap)
 test_data.Sex=test_data.Sex.map(genderMap )
thresh = 0.20
labelled_preds = [' '.join([learn_test.data.classes[i] for i,p in enumerate(pred)if p > thresh])for pred in preds]
fnames = [f.name[:-4] for f in learn_test.data.test_ds.x.items]
df = pd.DataFrame({'image_name':fnames, 'tags':labelled_preds}, columns=['image_name', 'tags'])
 df.to_csv('submission_020.csv', index=False )<save_to_csv>
X=np.array(train_data.drop('Survived',axis=1))
y=np.array(train_data['Survived'])
 X.shape
thresh = 0.21
labelled_preds = [' '.join([learn_test.data.classes[i] for i,p in enumerate(pred)if p > thresh])for pred in preds]
fnames = [f.name[:-4] for f in learn_test.data.test_ds.x.items]
df = pd.DataFrame({'image_name':fnames, 'tags':labelled_preds}, columns=['image_name', 'tags'])
 df.to_csv('submission_021.csv', index=False )<import_modules>
X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=47 )
import os
import numpy as np
import keras
import sklearn
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import confusion_matrix, precision_score, recall_score, accuracy_score<load_from_csv>
lr=LogisticRegression(solver='liblinear',multi_class='ovr')
 lr.fit(X_train,y_train )
data = pd.read_csv('.. /input/train.csv' )<split>
lr.score(X_test,y_test )
train_data = data.iloc[:,2:203]<prepare_x_and_y>
test_data['Survived']=lr.predict(test_data.drop(['PassengerId'],axis=1))
y = data.iloc[:,1]<split>
pd.read_csv('/kaggle/input/titanic/gender_submission.csv' )
X_train, X_test, y_train, y_test = train_test_split(train_data, y, test_size=0.2, random_state=142 )<import_modules>
Submission=test_data[['PassengerId','Survived']]
Submission.set_index('PassengerId',inplace=True )
from xgboost import XGBClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC, LinearSVC
from sklearn.ensemble import RandomForestClassifier,GradientBoostingClassifier, VotingClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB<train_model>
Submission.to_csv('Submission.csv' )