text_html_output_1.png
from sklearn import model_selection

from sklearn.compose import ColumnTransformer

from sklearn.metrics import confusion_matrix, classification_report, roc_curve

from sklearn.pipeline import Pipeline

import pandas as pd

df = pd.read_csv('/kaggle/input/titanic/train.csv')
submission_df = pd.read_csv('/kaggle/input/titanic/test.csv')
ids = pd.read_csv('/kaggle/input/titanic/test.csv')

num_features = list(X_test.select_dtypes(include=['int64', 'float64']).columns)
numeric_transformer = Pipeline(steps=[('imputer', SimpleImputer(strategy='median')), ('center', StandardScaler()), ('scale', MinMaxScaler())])
cat_features = list(X_test.select_dtypes(include=['object']).columns)
categorical_transformer = Pipeline(steps=[('imputer', SimpleImputer(strategy='constant', fill_value='missing')), ('onehot', OneHotEncoder(handle_unknown='ignore'))])
features_preprocessor = ColumnTransformer(transformers=[('num', numeric_transformer, num_features), ('cat', categorical_transformer, cat_features)])
logreg_model = Pipeline(steps=[('features_preprocessor', features_preprocessor), ('logreg', LogisticRegression())])
xgb_model = Pipeline(steps=[('features_preprocessor', features_preprocessor), ('xgb', XGBClassifier())])

def run_exps(X_train: pd.DataFrame, y_train: pd.DataFrame, X_test: pd.DataFrame, y_test: pd.DataFrame) -> pd.DataFrame:
    """
    Lightweight script to test many models and find winners
    :param X_train: training split
    :param y_train: training target vector
    :param X_test: test split
    :param y_test: test target vector
    :return: DataFrame of predictions
    """
    dfs = []
    models = [('Logistic Regression', logreg_model), ('XGBoost', xgb_model)]
    results = []
    names = []
    scoring = ['accuracy', 'precision_weighted', 'recall_weighted', 'f1_weighted', 'roc_auc']
    target_names = list(map(str, y_train.unique()))
    for name, model in models:
        kfold = model_selection.KFold(n_splits=5, shuffle=True, random_state=21)
        cv_results = model_selection.cross_validate(model, X_train, y_train, cv=kfold, scoring=scoring)
        clf = model.fit(X_train, y_train)
        y_pred = clf.predict(X_test)
    results.append(cv_results)
    names.append(name)
    this_df = pd.DataFrame(cv_results)
    this_df['model'] = name
    dfs.append(this_df)
    final = pd.concat(dfs, ignore_index=True)
    return final

models_results = run_exps(X_train, y_train, X_test, y_test)