ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

决策树之scikit-learn

2026/9/23 10:09:54 拓冰建站 浏览量
决策树之scikit-learn

实例

from sklearn.datasets import load_iris
from sklearn import tree
import matplotlib.pyplot as plt# Load iris dataset
iris = load_iris()
X, y = iris.data, iris.target# Fit the classifier
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, y)# Plot the decision tree
plt.figure(figsize=(15, 10))
tree.plot_tree(clf)
plt.show()

运行结果