sklearn树可视化中的这些列表是什么

时间:2018-12-19 16:37:05

标签: python scikit-learn graphviz decision-tree

我正在使用sklearn.tree.export_graphviz可视化决策树。

https://scikit-learn.org/stable/modules/generated/sklearn.tree.export_graphviz.html

所有节点中都有这些列表列表,而我一生都无法弄清它们是什么或如何摆脱它们。首先,我认为它们一定是样本。但是所有列表的大小都相同,并且样本不能表示为长度为2的列表。然后我以为它们要么是类名的表示,要么是杂质的表示,但是我禁用了两者都无效。我还禁用了ID,标签和杂质。这是一个多类别的多标签文本分类。

这是树代码:

def _create_classifier():
    decision_tree_classifier = DecisionTreeClassifier(
    criterion=CRITERION, # Gini
    splitter=SPLITTER,   # best
    min_samples_split=MIN_SAMPLES_SPLIT, # 4
    #max_features=MAX_FEATURES, # 50%
    max_depth=MAX_DEPTH, # 68
    presort=PRESORT # True
    )
return decision_tree_classifier

这是火车和出口。注意所有设置为False:

classifier.fit(X_train, y_train)

from sklearn.tree import export_graphviz
import os

path = 'dtree.dot'

with open(path, 'w') as dotfile:
     export_graphviz(classifier, out_file = dotfile, feature_names=all_features, filled=True, rounded=True, label=False, class_names=False, node_ids=False, impurity=False, proportion=True)
    print("EXPORTED")
os.system('dot -Tpng dtree.dot -o tree.png')

这是我的树:

enter image description here

1 个答案:

答案 0 :(得分:0)

找到了。是样品。该表示是PCA降维的前两个组成部分。

https://scikit-learn.org/stable/auto_examples/plot_multilabel.html