Jed Rembold
March 16, 2026

Need to import:
from sklearn.inspection import DecisionBoundaryDisplay as DBDCreate the plot from the estimator:
DBD.from_estimator(model, df[[features]])
Tidymodels doesn’t really have a comparable function to DecisionBoundaryDisplay, but it can be computed directly with other tools
Main idea is to compute a fine grid of points in feature-space that you’ll use to get predictions
pred_df <- expand.grid(
feat1 = seq(low, high, length.out=1000),
feat2 = seq(low, high, length.out=1000))Then get predictions from your model
pred_cat <- model_fit %>% predict(pred_df)Plot the results with a raster plot with the fill determined by the predicted label
ggplot(pred_df, aes(feat1, feat2, fill=.pred_class)) +
geom_raster(alpha = 0.5)




Import the classifier:
from sklearn.tree import DecisionTreeClassifierCreate your model:
tree = DecisionTreeClassifier()We will mention available options in just a moment, as they can be more important here
Everything else works the same as the logistic regression models!
You already have the model as part of the parsnip library
Create your model:
tree <- decision_tree(mode="classification")Everything else works the same as the logistic regression models!
Can also import a plotter for Matplotlib to sketch out nice trees
from sklearn.tree import plot_treeThen just pass the tree model after fitting it
plot_tree(tree)Can adjust the filled option to color
the nodes, or feature_names to show better
comparisons
You need another package to plot the decision trees nicely
library(rpart.plot)Then just pass the tree model after fitting it
rpart.plot(tree_fit$fit)Can adjust the type and
extra to different numbers to further
customize
Pre-pruning limits the tree’s size as it is build (pick one, maybe two)
max_depthmax_leaf_nodesmin_samples_splitmin_impurity_decreasetree_depthmin_nccp_alpha when
creating the treecost_complexity when
creating the treerandom_state option (or setting a
seed) in examples have been fixing this so far. But remove that and run
the same trial multiple timesIt can be useful to get an idea of what features are most important in constructing the tree
Once the model has been fit, you can query the model to get this information:
tree.feature_importances_This returns a list of relative importance for each feature, in the same order as the features you passed into the model originally
In R you need the vip library
library(vip)
vip(tree_fit)You can construct your own arbitrary ensembles
In Python:
combo = VotingClassifier(
[
('logreg',log_mod), # first model
('dec_tree',tree) # second model
],
voting='soft')
combo.fit(training_df[['x','y']])I haven’t yet found an equivalent in R, but I’d imagine it is out there
