构建决策树模型并绘制生成的决策树+export_graphviz

构建决策树模型,使用sklearn框架:

 

import pandas as pd
import numpy as np

from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import export_graphviz

# tongji_nochronic_member_benren_pd which is a pandas dataframe
X = tongji_nochronic_member_benren_pd[select2]
y = tongji_nochronic_member_benren_pd[["TimesLabel"]]
#y = tongji_nochronic_member_benren_pd[["PaymentLabel"]]

X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

clf = DecisionTreeClassifier(max_leaf_nodes=10, max_depth = 6, random_state=0,class_weight='balanced')
clf.fit(X_train, y_train)
生成的决策树的基本信息如下:

DecisionTreeClassifier(class_weight='balanced', criterion='gini', max_depth=6,
            max_features=None, max_leaf_nodes=10,
            min_impurity_decrease=0.0, min_impurity_split
上一篇:[Go]理解golang项目性能分析工具trace


下一篇:解决PyCharm用graphviz画决策树中文乱码问题