Kaggle competition: Titanic - Machine Learning from Disaster
data['GarageYrBlt'] = make_quantile_bins('GarageYrBlt', 10)
 analyse_categorical("GarageYrBlt", fillnan=5.0 )<data_type_conversions>
train_data= pd.read_csv('.. /input/titanic/train.csv')
 train_data.head(10 )
analyse_numeric("GarageArea" )<feature_engineering>
test_data=pd.read_csv('.. /input/titanic/test.csv')
 test_data.head()
data['GarageArea_Bin'] = make_quantile_bins('GarageArea', 10)
 analyse_categorical('GarageArea_Bin' )<data_type_conversions>
print(train_data.isnull().sum())
 print(test_data.isnull().sum() )
analyse_numeric('WoodDeckSF' )<feature_engineering>
features=['Pclass', 'Sex' ,'Age', 'SibSp', 'Parch' ,'Fare' ,'Embarked']
y=train_data.Survived
data["WoodDeckSF"] = np.where(data["WoodDeckSF"] == 0, 0, 1)
 analyse_categorical("WoodDeckSF" )<data_type_conversions>
train_data['Age']=train_data['Age'].fillna(train_data['Age'].mode() [0])
 train_data['Embarked']=train_data['Embarked'].fillna(train_data['Embarked'].mode() [0])
 test_data['Age']=test_data['Age'].fillna(test_data['Age'].mode() [0])
 test_data['Fare']=test_data['Fare'].fillna(test_data['Fare'].median() )
analyse_numeric('OpenPorchSF' )<feature_engineering>
train_data.isnull().sum()
test_data.isnull().sum()
X = pd.get_dummies(train_data[features])
 X_test = pd.get_dummies(test_data[features])
 X.head()
data["OpenPorchSF"] = np.where(data["OpenPorchSF"] == 0, 0, 1)
 analyse_categorical("OpenPorchSF" )<feature_engineering>
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=6)
 sc= StandardScaler()
x_train= sc.fit_transform(x_train)
 x_test =sc.transform(x_test)
 model = RandomForestClassifier(n_estimators=100, max_depth=5, random_state=1)
 model.fit(x_train, y_train)
 predictions = model.score(x_test,y_test)
 predictions
data["EnclosedPorch"] = np.where(data["EnclosedPorch"] == 0, 0, 1)
 analyse_categorical("EnclosedPorch" )<feature_engineering>
sc= StandardScaler()
X= sc.fit_transform(X)
 X_test =sc.transform(X_test)
 shuffle(X, y,random_state=6 )
data["3SsnPorch"] = np.where(data["3SsnPorch"] == 0, 0, 1)
 analyse_categorical("3SsnPorch" )<feature_engineering>
model.fit(X, y)
 predictions = model.predict(X_test)
 output = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': predictions})
 output.to_csv('my_submission.csv', index=False)
 print("Your submission was successfully saved!" )