泰坦尼克号生还预测
import pandas as pd
import numpy as np
import os
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score
from sklearn import metrics
def get_excel(path1):
df=pd.read_excel(path1,index=False)
return df
def chu_data(X_train):
X_train['Age'].replace(np.nan, np.nanmedian(X_train['Age']), inplace=True)
sns.distplot(X_train['Age'], hist=True, kde=True)
plt.show()
X_train.drop("Cabin", axis=1, inplace=True)
sns.countplot(x='Embarked', data=X_train)
plt.show()
X_train['Embarked'].replace(np.nan, 'S', inplace=True)
print(X_train[np.isnan(X_train['Fare'])])
pclass3_fares = X_train.query('Pclass==3&Embarked=="S"')['Fare']
pclass3_fares = pclass3_fares.replace(np.nan, 0)
median_fare = np.median(pclass3_fares)
X_train.loc[X_train['PassengerId'] == 1044, 'Fare'] = median_fare
X_train['Sex'].replace(['male', 'female']