决策树显示不出来?谢谢

来源:5-6 实战(1)

慕码人1499

2025-01-13

代码如下:
#visualize the tree
%matplotlib inline
from matplotlib import pyplot as plt
fig=plt.figure(figsize=(10,10))
tree.plot_tree(dc_tree,filled=True,feature_names=[‘SepalLength’,‘SepalWidth’,‘PetalLength’,‘PetalWidth’],class_names=[‘setosa’,‘versicolor’,‘virginica’])

显示如下:
[Text(0.4444444444444444, 0.9, ‘PetalWidth <= 0.8\nentropy = 1.585\nsamples = 150\nvalue = [50, 50, 50]\nclass = setosa’),
Text(0.3333333333333333, 0.7, ‘entropy = 0.0\nsamples = 50\nvalue = [50, 0, 0]\nclass = setosa’),
Text(0.38888888888888884, 0.8, 'True ‘),
Text(0.5555555555555556, 0.7, ‘PetalWidth <= 1.75\nentropy = 1.0\nsamples = 100\nvalue = [0, 50, 50]\nclass = versicolor’),
Text(0.5, 0.8, ’ False’),
Text(0.3333333333333333, 0.5, ‘PetalLength <= 4.95\nentropy = 0.445\nsamples = 54\nvalue = [0, 49, 5]\nclass = versicolor’),
Text(0.2222222222222222, 0.3, ‘SepalLength <= 5.15\nentropy = 0.146\nsamples = 48\nvalue = [0, 47, 1]\nclass = versicolor’),
Text(0.1111111111111111, 0.1, ‘entropy = 0.722\nsamples = 5\nvalue = [0, 4, 1]\nclass = versicolor’),
Text(0.3333333333333333, 0.1, ‘entropy = 0.0\nsamples = 43\nvalue = [0, 43, 0]\nclass = versicolor’),
Text(0.4444444444444444, 0.3, ‘entropy = 0.918\nsamples = 6\nvalue = [0, 2, 4]\nclass = virginica’),
Text(0.7777777777777778, 0.5, ‘PetalLength <= 4.95\nentropy = 0.151\nsamples = 46\nvalue = [0, 1, 45]\nclass = virginica’),
Text(0.6666666666666666, 0.3, ‘entropy = 0.65\nsamples = 6\nvalue = [0, 1, 5]\nclass = virginica’),
Text(0.8888888888888888, 0.3, ‘entropy = 0.0\nsamples = 40\nvalue = [0, 0, 40]\nclass = virginica’)]

写回答

1回答

flare_zhao

2025-01-22

可以加学习qq群,远程看下。

或者vx 454209979

0
0

Python3入门人工智能 掌握机器学习+深度学习

人工智能基础全方位讲解,构建完整人工智能知识体系,带你入门AI

2000 学习 · 605 问题

查看课程