学习中心
登录
已解决
决策树跟老师的结果不一样

参照老师代码写的,但是结果却不一样,我的根节点是是petal length。请老师帮忙看看哪里错了

e7b9b0f3810593d6a79216ba13e4cbe2.png

1df8b26b6c2a1a29bf56df7e5c564f9d.png

import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn import datasets
import graphviz
from sklearn.model_selection import train_test_split
from sklearn import tree
iris=datasets.load_iris()
X=iris['data']
y=iris['target']

feature_names=iris['feature_names']
print(feature_names)
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=256)
model=DecisionTreeClassifier()
model.fit(X_train,y_train)
print('测试数据得分为',model.score(X_test,y_test))
print('算法预测的结果:',model.predict(X_test))
print('真实结果为',y_test)

#逻辑斯蒂回归中手动计算过概率
model.predict_proba(X_test)

dot_data=tree.export_graphviz(model,filled=True,rounded=True,feature_names=feature_names)
graph=graphviz.Source(dot_data)
graph.view()
49 1
    1个回答
    你还没有查看该回答的权限哦~请先获取查看权限
    立即查看
    写回答