sklearn中决策树的API
使用kaggle上数据数据源
下面是使用sklearn生成决策树的python
import pandas as pd
from sklearn.feature_extraction import DictVectorizer
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier,export_graphviz
def decsion():
"""
决策树对泰坦尼克号存活进行预测
:return: None
"""
#获取数据
titanData = pd.read_csv("./data/Titanic/train.csv")
#处理数据,找出特征值和目标值。
x = titanData[['Pclass','Age','Sex']]
y = titanData['Survived']
#缺失值处理
x['Age'].fillna(x['Age'].mean(),inplace=True)