text_plain_output_1.png
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis

from sklearn.ensemble import RandomForestClassifier,GradientBoostingClassifier,VotingClassifier

from sklearn.impute import KNNImputer,IterativeImputer

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import classification_report

from sklearn.model_selection import train_test_split,cross_val_score,StratifiedKFold

from sklearn.neighbors import KNeighborsClassifier

from sklearn.svm import SVC

from sklearn.tree import DecisionTreeClassifier

import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import MinMaxScaler, RobustScaler, StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split, cross_val_score, StratifiedKFold
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import KNNImputer, IterativeImputer
from sklearn.feature_selection import SelectKBest, chi2, mutual_info_classif
from sklearn.linear_model import LogisticRegression
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.decomposition import PCA
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier, VotingClassifier
sns.set_style('whitegrid')
from sklearn.metrics import accuracy_score

train = pd.read_csv('/kaggle/input/titanic/train.csv')
test = pd.read_csv('/kaggle/input/titanic/test.csv')
submit = pd.DataFrame(test['PassengerId'])

train['title'] = 0
for i in range(0, len(train)):
    train.loc[i, 'title'] = train['Name'].iloc[i].split(',')[1].split('.')[0][1:]
train['title'].replace({'Mr': 1, 'Miss': 2, 'Mrs': 2, 'Master': 3, 'Dr': 4, 'Rev': 5}, inplace=True)
train['title'].replace(['Major', 'Mlle', 'Col', 'Don', 'the Countess', 'Sir', 'Capt', 'Mme', 'Lady', 'Jonkheer', 'Ms'], 6, inplace=True)

for i in range(len(train)):
    if not pd.isnull(train['Cabin'].iloc[i]):
        train.loc[i, 'Cabin'] = train['Cabin'].loc[i][0]
train['Cabin'].replace({'C': 1, 'B': 2, 'D': 3, 'E': 4, 'A': 5, 'F': 6, 'G': 7, 'T': 8}, inplace=True)
train['Fare'] = np.sqrt(train['Fare'])

train.drop(['Name', 'SibSp', 'Parch', 'Ticket', 'PassengerId', 'Cabin'], axis=1, inplace=True)

fig,ax=plt.subplots(3,1,figsize=(15,13))
sns.heatmap(train.corr('spearman'),annot=True,ax=ax[0],label='spearman')    #spearman 
sns.heatmap(train.corr('kendall'),annot=True,ax=ax[1],label='kendall')      #Kendall
sns.heatmap(train.corr('pearson'),annot=True,ax=ax[2],label='pearson')      #pearson  

train = pd.get_dummies(train, columns=['Pclass', 'Embarked', 'title', 'family'], drop_first=True)
impute = KNNImputer(n_neighbors=13)
train = pd.DataFrame(impute.fit_transform(train), columns=train.columns)

model = []
model.append(('Logistic Regression', LogisticRegression(max_iter=1000)))
model.append(('LDA', LinearDiscriminantAnalysis()))
model.append(('SVC', SVC(kernel='rbf')))
model.append(('DTC', DecisionTreeClassifier()))
model.append(('GBC', GradientBoostingClassifier()))
model.append(('RFC', RandomForestClassifier()))
model.append(('Kneig', KNeighborsClassifier()))
x = train.drop('Survived', axis=1)
y = train['Survived']
xtrain, xvalid, ytrain, yvalid = train_test_split(x, y, test_size=0.3)

from sklearn.metrics import classification_report
model = LogisticRegression(max_iter=3000)
model.fit(xtrain, ytrain)
ypred = model.predict(xvalid)
print(classification_report(yvalid, ypred))