ML之DT:基于DT算法对泰坦尼克号乘客数据集进行二分类(是否获救)预测
ML之DT:基于DT算法对泰坦尼克号乘客数据集进行二分类(是否获救)预测
输出结果
设计思路
核心代码
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state = 33)
vec = DictVectorizer(sparse=False)
X_train = vec.fit_transform(X_train.to_dict(orient='record'))
X_test = vec.transform(X_test.to_dict(orient='record'))
dtc = DecisionTreeClassifier()
dtc.fit(X_train, y_train)
y_predict = dtc.predict(X_test)
dtc.score(X_test, y_test))
classification_report(y_predict, y_test, target_names = ['died', 'survived'])
赞 (0)