kaggle 泰坦尼克号生还者预测

import pandas as pd
from sklearn.tree import DecisionTreeClassifier #决策树
from sklearn.model_selection import cross_val_score
df = pd.read_csv("train.csv")
#数据清洗,补全有缺失的数据
df.Age.fillna(df.Age.mean(),inplace = True)
#将female,male替换成数字1 0
df["Sex_int"] = df["Sex"].map({"female":1 , "male":0})
# print(df.info())
#选择特征
X = df[["Sex_int", "Age" , "Pclass"]]
y = df.Survived
model = DecisionTreeClassifier()
scores = cross_val_score(model , X , y , cv= 10 )
print(scores)
print(scores.mean())


你可能感兴趣的:(工作相关)