Kaggle competition: Titanic - Machine Learning from Disaster
features_addsub = features_add.drop(['Utilities', 'Street', 'PoolQC',], axis=1)
 features_addsub<feature_engineering>
train_data = pd.read_csv('/kaggle/input/titanic/train.csv')
 train_data.head()
features_pure_log = features_addsub.apply(lambda x: np.log1p(x))
features_pure_log<prepare_x_and_y>
train_data.isnull().sum()
train = features_pure_log.iloc[:1460]
train1 = features_pure_log.iloc[:1460]<split>
train_data = pd.get_dummies(train_data, columns = ['Pclass', 'Sex', 'Embarked'])
 train_data
X_train, X_test, y_train, y_test = train_test_split(train1, target, test_size=0.5, random_state=21 )<import_modules>
y_train = train_data['Survived']
X_train = train_data.copy().drop(['Survived', 'Age', 'Name', 'PassengerId', 'SibSp', 'Parch', 'Ticket', 'Cabin'], axis=1)
 X_train
from sklearn.preprocessing import RobustScaler, StandardScaler, MinMaxScaler
from sklearn.linear_model import ElasticNetCV, LassoCV, RidgeCV
from sklearn.svm import SVR
from sklearn.ensemble import GradientBoostingRegressor, AdaBoostRegressor, StackingRegressor
from xgboost import XGBRegressor
from lightgbm import LGBMRegressor
from sklearn.model_selection import KFold, cross_val_score
from sklearn.pipeline import make_pipeline<compute_test_metric>
test_data = pd.read_csv('/kaggle/input/titanic/test.csv')
 test_data = pd.get_dummies(test_data, columns = ['Pclass', 'Sex', 'Embarked'])
 test_data
def rmsle(estimator, x, y):
rmsle = np.sqrt(mean_squared_error(y, estimator.predict(x)))
 print(f"RMSLE score : {rmsle}" )<choose_model_class>
test_data.isnull().sum()
kfolds = KFold(n_splits=10, shuffle=True, random_state=12 )<train_on_grid>
X_test = test_data.copy().drop(['Name', 'Age', 'PassengerId', 'SibSp', 'Parch', 'Ticket', 'Cabin'], axis=1)
 X_test.fillna(X_test['Fare'].mean() , inplace=True)
 X_test, X_test.isnull().sum()
ridge = make_pipeline(RobustScaler() , RidgeCV(alphas=np.linspace(10, 200, 10),
scoring="neg_mean_squared_error", cv=kfolds))
ridge.fit(X_train, y_train)
 rmsle(ridge, X_test, y_test )<train_on_grid>
logr = LogisticRegression().fit(X_train,y_train)
 logr.predict(X_test)
 logr.score(X_train, y_train )
lasso = make_pipeline(RobustScaler() , LassoCV(cv=kfolds, max_iter=1e7, random_state=23))
lasso.fit(X_train, y_train)
 rmsle(lasso, X_test, y_test )<train_model>
dt = DecisionTreeClassifier().fit(X_train,y_train)
 dt.predict(X_test)
 dt.score(X_train, y_train), dt.feature_importances_
elastic = make_pipeline(RobustScaler() , ElasticNetCV(max_iter=1e7, cv=kfolds, random_state=32))
elastic.fit(X_train, y_train)
 rmsle(elastic, X_test, y_test )<train_model>
rf = RandomForestClassifier().fit(X_train,y_train)
 y_test = rf.predict(X_test)
 rf.score(X_train, y_train), rf.feature_importances_
svr = make_pipeline(RobustScaler() , SVR(kernel='poly' , C=1., degree=1,
gamma='auto', epsilon=0.001))
svr.fit(X_train, y_train)
 rmsle(svr, X_test, y_test )<train_model>
submission = pd.DataFrame({'PassengerId': np.arange(892, 892 + len(list(y_test))), 'Survived': list(y_test)})
 submission.to_csv('my_submission.csv', index=False )