Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<count_missing_values>
import pandas as pd
import numpy as np
import seaborn as sns
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.multioutput import MultiOutputRegressor
from sklearn.metrics import mean_absolute_error
nullity=combine.isnull().sum() [ combine.isnull().sum() != 0]
nullity, nullity.shape<count_values>
train = pd.read_csv('.. /input/titanic/train.csv')
 test = pd.read_csv('.. /input/titanic/test.csv')
 df=pd.concat([train,test] ).reset_index()
combine.MSZoning.value_counts()<count_values>
df[df['Embarked'].isnull() ]
combine['MSZoning']=combine['MSZoning'].fillna('None')
 combine.MSZoning.value_counts()<groupby>
df['Embarked']=df['Embarked'].fillna('S' )
combine['LotFrontage']=combine.groupby('Neighborhood')['LotFrontage'].transform(lambda x:x.fillna(x.median()))<count_values>
df[df['Fare'].isnull() ]
combine.Alley.value_counts()<count_values>
t=df[(df['Embarked']=='S')&(df['Pclass']==3)]['Fare'].median()
df['Fare']=df['Fare'].fillna(t )
combine['Alley']=combine['Alley'].fillna('None')
 combine.Alley.value_counts()<count_values>
Y, X = dmatrices('Survived ~ Pclass+Sex+Fare', df, return_type='dataframe')
 vif = pd.DataFrame()
vif["VIF Factor"] = [variance_inflation_factor(X.values, i)for i in range(X.shape[1])]
vif["features"] = X.columns
vif
combine.Utilities.value_counts()<count_values>
y = train["Survived"]
h=train[(train['Embarked']=='S')&(train['Pclass']==3)]['Fare'].median()
train['Fare']=train['Fare'].fillna(h)
 l=test[(test['Embarked']=='S')&(test['Pclass']==3)]['Fare'].median()
test['Fare']=test['Fare'].fillna(l)
 features = ["Pclass", "Sex", "Fare"]
X = pd.get_dummies(train[features])
 X_test = pd.get_dummies(test[features])
 model = RandomForestClassifier(n_estimators=1000, max_depth=5, random_state=1)
 model.fit(X, y)
 predictions = model.predict(X_test)
 output = pd.DataFrame({'PassengerId': test.PassengerId, 'Survived': predictions})
 output.to_csv('final_submission.csv', index=False )