plot_dt_regressor_tree#
- er_evaluation.plot_dt_regressor_tree(dt_regressor, feature_names)[source]#
Creates a tree plot of a decision tree regressor.
- Parameters:
dt_regressor (DecisionTreeRegressor) β A fitted decision tree regressor model.
X (numpy array or pandas DataFrame) β The input features used to fit the model.
y (numpy array or pandas Series) β The target values used to fit the model.
feature_names (list of str) β The names of the input features.
weights (Series, optional) β Sampling weights for y. Default is None.
label (str, optional) β The label for the color scale. Default is βValueβ.
color_function (function, optional) β A function applied to the subset of y values within each node to determine node color.If None, the predicted value for each node will be used as the color. Default is None.
- Returns:
A tree plot of the decision tree regressor.
- Return type:
plotly.graph_objs.Figure
Examples
>>> from sklearn.tree import DecisionTreeRegressor >>> import numpy as np >>> X = np.array([[1], [2], [3], [4], [5]]) >>> y = np.array([0, 1, 0, 1, 0]) >>> dt_regressor = DecisionTreeRegressor(max_depth=2) >>> dt_regressor.fit(X, y) >>> feature_names = ['x'] >>> plot_dt_regressor_tree(dt_regressor, feature_names)