python - 需要使用 Python 进行决策树可视化 GraphViz 使用 10-fold
问题描述
我有一个代码,我需要在 Python 中使用 GraphViz 可视化决策树的输出。采用 10 折交叉验证来获得相当充分的评估指标。只需要graphviz的指南
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import StandardScaler, LabelEncoder
from sklearn.model_selection import cross_val_score
from sklearn.metrics import make_scorer
from sklearn.model_selection import cross_validate
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
from sklearn import tree
data = pd.read_csv("goddess_2.csv")
label_Label = LabelEncoder()
data["Label"] = label_Label.fit_transform(data['Label'])
X = data.drop("Label", axis = 1)
y = data['Label']
#Decision Tree Binary Class Classifier Model Building
model = DecisionTreeClassifier()
scoring = ['accuracy','precision_weighted', 'recall_weighted','f1_weighted']
scores = cross_validate(model, X, y, cv=10,scoring=scoring)
Accuracy = scores['test_accuracy'].mean()
Precision = scores['test_precision_weighted'].mean()
Recall = scores['test_recall_weighted'].mean()
F1Score= scores['test_f1_weighted'].mean()
print("********** Decision Tree *********")
print("\n")
print("Accuracy,",round(Accuracy * 100,3))
print("\n")
print("Precision,",round(Precision * 100,4))
print("\n")
print("Recall,",round(Recall * 100,4))
print("\n")
print("F1-Score,",round(F1Score * 100,4))
print("\n")
clf = DecisionTreeClassifier(random_state=1234)
model = clf.fit(X, y)
text_representation = tree.export_text(clf)
print(text_representation)
解决方案
推荐阅读
- python - 如何将 JSON 传递给 REST API (IBKR)
- c++ - MakeFile C++ 问题只有 .Object 文件
- javascript - 如何正确实现无限加载器?
- javascript - Codewars Kata - 4th Kyu - Codewars 风格排名系统 - “+1 问题”
- cloud-foundry - Pivotal Cloud Foundry 基于容器或 VM
- c# - 使用检查查找超集的 Linq 查询
- php - WP 查询和 ACF 字段
- java - 如何在编辑文本上显示单选按钮的值?
- c# - 我是否需要在包装方法中等待任务
- python - 如何在更新的 json 文件中获取最后日期?