<jupyter_start><jupyter_text>**Titanic competition**  1. Importing packages<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
sns.set(style="whitegrid", color_codes=True)
%matplotlib inline<jupyter_output><empty_output><jupyter_text>2. Reading data from csv file<jupyter_code>df = pd.read_csv('train.csv', index_col='PassengerId')
df.head()<jupyter_output><empty_output><jupyter_text>3. Checking data for missing values, distributions and use descriptive statistics  3.1. Shape of Data Frame<jupyter_code>print('Shape of Data Frame is {}x{}'.format(*df.shape))<jupyter_output>Shape of Data Frame is 891x11<jupyter_text>3.2. Check missing values<jupyter_code>df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Int64Index: 891 entries, 1 to 891
Data columns (total 11 columns):
Survived    891 non-null int64
Pclass      891 non-null int64
Name        891 non-null object
Sex         891 non-null object
Age         714 non-null float64
SibSp       891 non-null int64
Parch       891 non-null int64
Ticket      891 non-null object
Fare        891 non-null float64
Cabin       204 non-null object
Embarked    889 non-null object
dtypes: float64(2), int64(4), object(5)
memory usage: 83.5+ KB<jupyter_text>+ **we can see that our data have missing values (_Age, Cabin, Embarked_)****Okey, let's plot heatmap to visualize missing values**<jupyter_code>sns.heatmap(df.isnull(), cbar=False).set_title("Missing values heatmap");<jupyter_output><empty_output><jupyter_text>**"Canin" and "Age" have many missing values**  3.3. Descriptive statistics<jupyter_code>df.describe(include='all')<jupyter_output><empty_output><jupyter_text>3.4. Pair plot<jupyter_code>sns.pairplot(df, hue='Survived', diag_kind='auto');<jupyter_output><empty_output><jupyter_text>3.5. Box plots<jupyter_code>f, axes = plt.subplots(1, 2, figsize=(16,8));

sns.boxplot(y='Age', x='Pclass', data=df, ax=axes[0]);
sns.boxplot(y='Age', x='Pclass', hue='Survived', data=df, ax=axes[1]);
f, axes = plt.subplots(1, 1, figsize=(8,8));

sns.boxplot(y='Fare', x='Survived', hue='Survived', data=df[df['Fare'] < 150], ax=axes);
f, axes = plt.subplots(1, 2, figsize=(16,8))

sns.boxplot(y='Fare', x='Embarked', data=df[df['Fare'] < 200], ax=axes[0], palette="husl")
sns.boxplot(y='Fare', x='Embarked', hue='Survived', data=df[df['Fare'] < 200], ax=axes[1], palette="husl")<jupyter_output><empty_output><jupyter_text>3.6. Count plots<jupyter_code>pd.crosstab(df['Embarked'], df['Survived'])
sns.countplot(x='Embarked', hue='Survived', data=df);
pd.crosstab(df['Embarked'].where((df['Pclass'] == 1)), df['Survived'].where((df['Pclass'] == 1)))
sns.countplot(x='Embarked', hue='Survived', data=df.where((df['Pclass'] == 1) & (df['Sex'] == 'female')));
sns.countplot(x='Embarked', hue='Survived', 
              data=df.where((df['Pclass'] == 1) & 
                            (df['Sex'] == 'female') &
                            (df['Cabin'].dropna().apply(lambda x: x[0]).astype(str) == 'B')));
df['Embarked'].value_counts()
df.loc[df['Survived'] == 1, 'Embarked'].value_counts()<jupyter_output><empty_output><jupyter_text>3.7 Correlation matrix<jupyter_code>corr = df.corr()
sns.heatmap(corr);<jupyter_output><empty_output><jupyter_text>4. Feature engineering and filling missing values<jupyter_code>from sklearn.preprocessing import StandardScaler
df[df['Embarked'].isna()]
def preproces_name(df):
    title_dict = {'Capt': 'Officer',
                  'Col': 'Officer',
                  'Major': 'Officer',
                  'Jonkheer': 'Royalty',
                  'Don': 'Royalty',
                  'Sir': 'Royalty',
                  'Dr': 'Officer',
                  'Rev': 'Officer',
                  'the Countess': 'Royalty',
                  'Mme': 'Mrs',
                  'Mlle': 'Miss',
                  'Ms': 'Miss',
                  'Mr': 'Mr',
                  'Mrs': 'Mrs',
                  'Miss': 'Miss',
                  'Master': 'Master',
                  'Lady': 'Royalty'
                 
                 }
    
    df['Title'] = df['Name'].map(lambda x: x.split(',')[1].split('.')[0].strip())
    df['Title'] = df['Title'].map(title_dict)
    
    return df
def preproces_fm_size(df):
    df['FamilySize'] = df['SibSp'] + df['Parch'] + 1
    
    df['travelled_alone'] = 0
    df.loc[df['FamilySize'] == 1, 'travelled_alone'] = 1
    
    return df
def preproces_pclass(df):
    df['Pclass'] = df['Pclass'].astype(str)
    df.loc[ df['Pclass'] == '1', 'Pclass'] = "Class1"
    df.loc[ df['Pclass'] == '2', 'Pclass'] = "Class2"
    df.loc[ df['Pclass'] == '3', 'Pclass'] = "Class3"
    
    return df
# le_embarked = LabelEncoder()
# le_sex = LabelEncoder()
# le_title = LabelEncoder()
# le_fm = LabelEncoder()

# def preproces_cat_features_fit_transform(df):
#     # df['Embarked'] = le_embarked.fit_transform(df['Embarked'])
#     # df['Sex'] = le_sex.fit_transform(df['Sex'])
#     # df['Title'] = le_title.fit_transform(df['Title'])
#     # df['FamilySize'] = le_fm.fit_transform(df['FamilySize'])
#     encode_col_list = list(df.select_dtypes(include=['object']).columns)
#     for i in encode_col_list:
#         df = pd.concat([df,pd.get_dummies(df[i], prefix=i)],axis=1)
#         df.drop(i, axis = 1, inplace=True)
    
#     return df

def preproces_cat_features(df):
    # df['Embarked'] = le_embarked.transform(df['Embarked'])
    # df['Sex'] = le_sex.transform(df['Sex'])
    # df['Title'] = le_title.transform(df['Title'])
    # df['FamilySize'] = le_fm.transform(df['FamilySize'])
    encode_col_list = list(df.select_dtypes(include=['object']).columns)
    for i in encode_col_list:
        df = pd.concat([df,pd.get_dummies(df[i], prefix=i)],axis=1)
        df.drop(i, axis = 1, inplace=True)
    
    return df
def fill_age(df, row):
    grouped_train = df.groupby(['Sex', 'Pclass', 'Title'])
    grouped_median_train = grouped_train.median()
    grouped_median_train = grouped_median_train.reset_index()[['Sex', 'Pclass', 'Title', 'Age']]
    condition = (
        (grouped_median_train['Sex'] == row['Sex']) &
        (grouped_median_train['Title'] == row['Title']) &
        (grouped_median_train['Pclass'] == row['Pclass'])
    )
    if np.isnan(grouped_median_train[condition]['Age'].values[0]):
        condition = (
            (grouped_median_train['Sex'] == row['Sex']) &
            (grouped_median_train['Pclass'] == row['Pclass'])
        )
        
    return grouped_median_train[condition]['Age'].values[0]

def preproces_age(df):
    df['Age'] = df.apply(lambda row: fill_age(df, row) if np.isnan(row['Age']) else row['Age'], axis=1)
                
    df = preproces_Age_Class(df)
                
    df['Age'] = df['Age'].astype(int)
    df.loc[ df['Age'] <= 11, 'Age'] = 0
    df.loc[(df['Age'] > 11) & (df['Age'] <= 18), 'Age'] = 1
    df.loc[(df['Age'] > 18) & (df['Age'] <= 22), 'Age'] = 2
    df.loc[(df['Age'] > 22) & (df['Age'] <= 27), 'Age'] = 3
    df.loc[(df['Age'] > 27) & (df['Age'] <= 33), 'Age'] = 4
    df.loc[(df['Age'] > 33) & (df['Age'] <= 40), 'Age'] = 5
    df.loc[df['Age'] > 40, 'Age'] = 6
    
    df['Age'] = df['Age'].astype(str)
    df.loc[ df['Age'] == '0', 'Age'] = "Children"
    df.loc[ df['Age'] == '1', 'Age'] = "Teens"
    df.loc[ df['Age'] == '2', 'Age'] = "Youngsters"
    df.loc[ df['Age'] == '3', 'Age'] = "Young Adults"
    df.loc[ df['Age'] == '4', 'Age'] = "Adults"
    df.loc[ df['Age'] == '5', 'Age'] = "Middle Age"
    df.loc[ df['Age'] == '6', 'Age'] = "Senior"
    
    return df
def preproces_fare(df):
    for pclass in range(1, 4):
        print(pclass)
        median = df['Fare'].where((df['Pclass'] == pclass)).median()
        df['Fare'].where((df['Pclass'] == pclass)).fillna(median, inplace=True)
    
    df['Fare'].fillna(df['Fare'].median(), inplace=True)
    df = preproces_fare_per_person(df)
    
    df.loc[ df['Fare'] <= 7.91, 'Fare'] = 0
    df.loc[(df['Fare'] > 7.91) & (df['Fare'] <= 14.454), 'Fare'] = 1
    df.loc[(df['Fare'] > 14.454) & (df['Fare'] <= 31), 'Fare'] = 2
    df.loc[(df['Fare'] > 31) & (df['Fare'] <= 99), 'Fare'] = 3
    df.loc[(df['Fare'] > 99) & (df['Fare'] <= 250), 'Fare'] = 4
    df.loc[(df['Fare'] > 250), 'Fare'] = 5
    df['Fare'] = df['Fare'].astype(int)
    
    df['Fare'] = df['Fare'].astype(str)
    df.loc[ df['Fare'] == '0', 'Fare'] = "Extremely Low"
    df.loc[ df['Fare'] == '1', 'Fare'] = "Very Low"
    df.loc[ df['Fare'] == '2', 'Fare'] = "Low"
    df.loc[ df['Fare'] == '3', 'Fare'] = "High"
    df.loc[ df['Fare'] == '4', 'Fare'] = "Very High"
    df.loc[ df['Fare'] == '5', 'Fare'] = "Extremely High"
    
    return df
def preproces_cabin(df):
    df['Cabin'] = df['Cabin'].fillna('Other')
    
    df['Cabin'] = df['Cabin'].map(lambda x: x[0])
    
    return df
def preproces_Age_Class(df):
    df['Age_Class']= df['Age'] * df['Pclass']
    
    return df
def preproces_fare_per_person(df):
    df['Fare_Per_Person'] = df['Fare'] / (df['FamilySize'])
    df['Fare_Per_Person'] = df['Fare_Per_Person'].astype(int)
    
    return df
# def preprocese_cabin_count(df):
#     df['Cabin_count'] = 
# preproces_cabin(df)
# df['Cabin'].value_counts()
scaler = StandardScaler()
def preproces_features(df, train=True):
    global scaler
    df = preproces_name(df)
    df = preproces_fm_size(df)
    df = df.drop('Cabin', axis=1)
#     df = preproces_cabin(df)
    
    df['Embarked'] = df['Embarked'].fillna('S')
#     df['Duplicate_ticket'] = 
    
    df = preproces_fare(df)
    
    df['Sex'] = df['Sex'].map({'male': 1, 'female': 0}).astype(int)
    
    if train:
        df = df.drop(['Ticket', 'Survived', 'Name'], axis=1)
        df = preproces_age(df)
        df = preproces_pclass(df)
#         df = preproces_cat_features(df) #_fit_transform(df)
        # df = preproces_age_clf(df)
        # df['Pclass', 'Age', 'SibSp', 'Parch', 'Fare'] 
        df[['SibSp', 'Parch', 'FamilySize', 'Fare_Per_Person', 'Age_Class']] = scaler.fit_transform(df[['SibSp', 'Parch', 'FamilySize','Fare_Per_Person', 'Age_Class']])
    else:
        df = df.drop(['Ticket', 'Name'], axis=1)
        df = preproces_age(df)
        df = preproces_pclass(df)
#         df = preproces_cat_features(df)
        df[['SibSp', 'Parch', 'FamilySize', 'Fare_Per_Person', 'Age_Class']] = scaler.transform(df[['SibSp','Parch', 'FamilySize','Fare_Per_Person', 'Age_Class']])
    
    return df
y = df['Survived']
train_df = preproces_features(df.copy())
train_df.info()
cat_features = np.where((train_df[train_df.columns].dtypes != np.float64))[0]
cat_features
cat_features = train_df.columns[cat_features]
df.head()
train_df.head()
title_column = list(set([x if ('Fare' in x) else '' for x in train_df.columns]))
title_column.remove('')
title_column.remove('Fare_Per_Person')
train_df[title_column].mean() * len(train_df)<jupyter_output><empty_output><jupyter_text>5. PCA, TSNE, MDS and correlation matrix<jupyter_code>from sklearn.decomposition import PCA

model_pca = PCA(n_components=2)
X_pca =  model_pca.fit_transform(train_df)

sns.scatterplot(X_pca[:, 0], X_pca[:, 1], hue=y_train)

from mpl_toolkits.mplot3d import Axes3D


model_pca = PCA(n_components=3)
X_pca =  model_pca.fit_transform(train_df)

X1 = []
X0 = []
for i, yy in enumerate(y_train):
    if yy == 1:
        X1.append(list(X_pca[i]))
    else:
        X0.append(list(X_pca[i]))
        
X0 = np.array(X0)
X1 = np.array(X1)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X0[:, 0], X0[:, 1], X0[:, 2], c='red', s=20)
ax.scatter(X1[:, 0], X1[:, 1], X1[:, 2], c='green', s=20)
ax.view_init(30, 185)
plt.show()
from sklearn.manifold import TSNE

model_tsne = TSNE(n_components=2)
X_tsne =  model_tsne.fit_transform(train_df)

sns.scatterplot(X_tsne[:, 0], X_tsne[:, 1], hue=y_train)
from mpl_toolkits.mplot3d import Axes3D

model_tsne = TSNE(n_components=3)
X_tsne =  model_tsne.fit_transform(train_df)

X1 = []
X0 = []
for i, yy in enumerate(y_train):
    if yy == 1:
        X1.append(list(X_tsne[i]))
    else:
        X0.append(list(X_tsne[i]))
        
X0 = np.array(X0)
X1 = np.array(X1)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X0[:, 0], X0[:, 1], X0[:, 2], c='red', s=10)
ax.scatter(X1[:, 0], X1[:, 1], X1[:, 2], c='green', s=10)
ax.view_init(30, 185)
plt.show()
from sklearn.manifold import MDS

model_mds = MDS(n_components=2)
X_mds =  model_mds.fit_transform(train_df)

sns.scatterplot(X_mds[:, 0], X_mds[:, 1], hue=y_train)
from mpl_toolkits.mplot3d import Axes3D

model_mds = MDS(n_components=3)
X_mds =  model_mds.fit_transform(train_df)

X1 = []
X0 = []
for i, yy in enumerate(y_train):
    if yy == 1:
        X1.append(list(X_mds[i]))
    else:
        X0.append(list(X_mds[i]))
        
X0 = np.array(X0)
X1 = np.array(X1)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X0[:, 0], X0[:, 1], X0[:, 2], c='red', s=20)
ax.scatter(X1[:, 0], X1[:, 1], X1[:, 2], c='green', s=20)
ax.view_init(30, 185)
plt.show()<jupyter_output><empty_output><jupyter_text>6. Prediction model<jupyter_code>from sklearn.model_selection import cross_val_score, StratifiedKFold, train_test_split, GridSearchCV
from sklearn.metrics import classification_report
X_train, X_test, y_train, y_test = train_test_split(train_df, y, shuffle=True, random_state=17, test_size=0.2)
kf = StratifiedKFold(n_splits=3, shuffle=True, random_state=17)
from xgboost.sklearn import XGBClassifier
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from catboost import CatBoostClassifier
best_xgb_clf = None

def xgb_clf(train_df=None, y_train=None, test_df=None, cv=5):
    global best_xgb_clf
    scoring = 'accuracy'

    params = {
        'n_estimators': [500, 1000],
        'max_depth': [6 , 7, 8, 9],
        'learning_rate': [0.01, 0.05, 0.001],
        'reg_alpha': np.linspace(1, 2, 4),
        'reg_lambda': np.linspace(4, 5, 4)
    }
    
    xgb_model = XGBClassifier(objective='binary:logistic', nthreads=2)
    
    grid = GridSearchCV(xgb_model, param_grid=params, n_jobs=-1, verbose=1, scoring=scoring, cv=cv)
    
    grid.fit(train_df, y_train)
    
    best_xgb_clf = grid.best_estimator_
    print(grid.best_params_, grid.best_score_)
    
    prediction = best_xgb_clf.predict(test_df)
    
    return prediction
best_svc = None
def svm_clf(train_df=None, y_train=None, test_df=None, cv=5):
    global best_svc
    scoring = 'accuracy'
    params = {
        #'C': [0.1, 0.5, 1, 5, 0.55, 0.45],
        'C': np.linspace(0.5, 2, 100),
        'kernel': ['linear', 'poly', 'rbf', 'sigmoid'],
        'gamma': [*np.logspace(-9, 3, 5), 'scale'],
        'tol': [0.001, 0.01, 0.0001],
#         'class_weight':['balanced'],
        'decision_function_shape' : ['ovo', 'ovr'],
        'tol': [0.001],
#         'gamma': ['scale'],
        'kernel': ['rbf'],
        'random_state': [0],
        #'C': [0.1653061224489796],
        'decision_function_shape' : ['ovo']
    }
    
    svc_model = SVC()
    grid = GridSearchCV(svc_model, param_grid=params, n_jobs=-1, verbose=1, scoring=scoring, cv=cv)
    grid.fit(train_df, y_train)
    
    best_svc = grid.best_estimator_
    print(grid.best_params_, grid.best_score_)
    
    prediction = best_svc.predict(test_df)
    
    return prediction
log_reg = None
def log_reg_clf(train_df=None, y_train=None, test_df=None, cv=5):
    global log_reg
    scoring = 'accuracy'
    params = {
        #'C': [0.1, 0.5, 1, 5, 0.55, 0.45, 0.9],
        'C': np.linspace(0.1, 2, 50),
        # 'penalty': ['l1', 'l2'],
        
        'penalty': ['l2'],
        'tol': [0.001],
        'max_iter': [100, 1000],
        #'random_state': [0],
        #'C': [0.94081632653061231],
        'solver': ['newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga']
    }
    
    log_reg = LogisticRegression()
    grid = GridSearchCV(log_reg, param_grid=params, n_jobs=-1, verbose=1, scoring=scoring, cv=cv)
    grid.fit(train_df, y_train)
    
    log_reg = grid.best_estimator_
    print(grid.best_params_, grid.best_score_)
    
    prediction = log_reg.predict(test_df)
    
    return prediction
best_rf = None
def rf_clf(train_df=None, y_train=None, test_df=None, cv=5):
    global best_rf
    scoring = 'accuracy'
    params = { 
        'n_estimators': [200, 500],
        'max_features': ['auto', 'sqrt', 'log2'],
        'max_depth' : [4, 5, 6, 7, 8],
        'criterion' :['gini', 'entropy']
    }
    
    best_rf = RandomForestClassifier(random_state=42)
    grid = GridSearchCV(best_rf, param_grid=params, n_jobs=-1, verbose=1, scoring=scoring, cv=cv)
    grid.fit(train_df, y_train)
    
    best_rf = grid.best_estimator_
    print(grid.best_params_, grid.best_score_)
    
    prediction = best_rf.predict(test_df)
    
    return prediction
best_gb = None
def gb_clf(train_df=None, y_train=None, test_df=None, cv=5):
    global best_rf
    scoring = 'accuracy'
    params = { 
        "learning_rate": [0.01, 0.05, 0.001],
        "min_samples_split": np.linspace(0.1, 0.5, 5),
        "min_samples_leaf": np.linspace(0.1, 0.5, 5),
        "max_depth":[3,5,8],
        "max_features":["log2","sqrt"],
        "criterion": ["friedman_mse",  "mae"],
        "subsample":np.linspace(0.5, 1, 5),
        "n_estimators":[10]
    }
    
    best_gb = GradientBoostingClassifier(random_state=42)
    grid = GridSearchCV(best_gb, param_grid=params, n_jobs=-1, verbose=1, scoring=scoring, cv=cv)
    grid.fit(train_df, y_train)
    
    best_gb = grid.best_estimator_
    print(grid.best_params_, grid.best_score_)
    
    prediction = best_gb.predict(test_df)
    
    return prediction
best_cat = None
def cat_clf(train_df=None, y_train=None, test_df=None, cv=5):
    global best_cat
    scoring = 'accuracy'
    params = { 
        'iterations': [500],
        'depth': [4, 5, 8],
#         'learning_rate' : [4, 5, 6, 7, 8],
        'loss_function': ['Logloss', 'CrossEntropy'],
        'l2_leaf_reg': np.logspace(-20, -19, 3),
    }
    
    best_cat = CatBoostClassifier()
    grid = GridSearchCV(best_cat, param_grid=params, verbose=1, cv=cv)
    grid.fit(train_df, y_train, cat_features=cat_features, verbose=False)
    
    best_cat = grid.best_estimator_
    print(grid.best_params_, grid.best_score_)
    
    prediction = best_cat.predict(test_df)
    
    return prediction
model = CatBoostClassifier(iterations=500,
                           depth=2,
                           learning_rate=1,
                           loss_function='Logloss',
                           verbose=False)
model.fit(X_train, y_train, cat_features=cat_features)
test_df = pd.read_csv('test.csv', index_col='PassengerId')
test_df.info()
test = preproces_features(test_df.copy(), train=False)
test.info()
test[test['Title'].isna()]
test['Title'].fillna('na', inplace=True)
test['Title_Royalty'] = 0
# test['Cabin_T'] = 0
test = test[train_df.columns]
test.head()
pred_rf = rf_clf(test_df=X_test, train_df=train_df, y_train=y, cv=kf)
pred_gb = gb_clf(test_df=X_test, train_df=train_df, y_train=y, cv=kf)
pred_xgb = xgb_clf(test_df=X_test, train_df=train_df, y_train=y, cv=kf)
pred_svm = svm_clf(test_df=X_test, train_df=train_df, y_train=y, cv=kf)
pred_log = log_reg_clf(test_df=X_test, train_df=train_df, y_train=y, cv=kf)
pred_cat = cat_clf(test_df=X_test, train_df=train_df, y_train=y, cv=kf)
# best_xgb_clf.get_params()
# best_svc.get_params()
# log_reg.get_params()
gender_subm = pd.read_csv('gender_submission.csv')
gender_subm.head()
from sklearn.metrics import classification_report
print(classification_report(y_test, pred_rf))
print(cross_val_score(best_rf, X_test, y=y_test, cv=10).mean())
print(classification_report(y_test, pred_gb))
print(cross_val_score(best_gb, X_test, y=y_test, cv=10).mean())
print(classification_report(y_test, pred_log))
print(cross_val_score(log_reg, X_test, y=y_test, cv=10).mean())
print(classification_report(y_test, pred_svm))
print(cross_val_score(best_svc, X_test, y=y_test, cv=10).mean())
print(classification_report(y_test, pred_xgb))
print(cross_val_score(best_xgb_clf, X_test, y=y_test, cv=10).mean())
print(classification_report(y_test, pred_cat))
print(cross_val_score(best_cat, X_test, y=y_test, cv=10).mean())<jupyter_output>precision    recall  f1-score   support

           0       0.84      0.87      0.86       106
           1       0.80      0.77      0.78        73

   micro avg       0.83      0.83      0.83       179
   macro avg       0.82      0.82      0.82       179
weighted avg       0.83      0.83      0.83       179<jupyter_text>7. Get prediction for test<jupyter_code>pred_svc = best_svc.predict(test)
pred_rf = best_rf.predict(test)
pred_xgb = best_xgb_clf.predict(test)
pred_log = log_reg.predict(test)
test.info()
pred_cat = best_cat.predict(test).astype(int)
gender_subm['Survived'] = pred_svc
gender_subm.to_csv('my_subm_svc.csv', index=False)

gender_subm['Survived'] = pred_rf
gender_subm.to_csv('my_subm_rf.csv', index=False)

gender_subm['Survived'] = pred_xgb
gender_subm.to_csv('my_subm_xgb.csv', index=False)

gender_subm['Survived'] = pred_log
gender_subm.to_csv('my_subm_log.csv', index=False)
gender_subm['Survived'] = pred_cat
gender_subm.to_csv('my_subm_cat.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.177981220657277, 'fraction_numerical': 0.030892018779342723, 'mean_word_length': 3.6866886688668865, 'pattern_counts': {'":': 8, '<': 69, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '493635', 'license': 'MIT', 'n_tokens_mistral': 8927, 'n_tokens_neox': 8386, 'n_words': 1483, 'path': 'kaggle/Titanic/titanic.ipynb', 'repo_name': 'kryvokhyzha/examples-and-courses', 'size': '21300'}