We can visualize decision tree with training set distribution, for example
from matplotlib import pyplot as plt
from sklearn import datasets
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
# Prepare the data data, can do row sample and column sample here
iris = datasets.load_iris()
X = iris.data
y = iris.target
# Fit the classifier with default hyper-parameters
clf = DecisionTreeClassifier(random_state=1234)
clf.fit(X, y)
fig = plt.figure(figsize=(25,20))
_ = tree.plot_tree(clf,
feature_names=iris.feature_names,
class_names=iris.target_names,
filled=True)
gives us
with distribution of training set, for example value = [50, 50, 50] in the root node.
However, I am not able to give it a test set, and get the distribution of test set in the visualized tree.