Clear Filters
Clear Filters

PDP plots for ensembled tree from matlab classification learner app

1 view (last 30 days)
Hello all,
I hope you are doing well.
Just a simple question. I wanted to plot the PDP (Partial Dependence Plots). I have used classification learner app and got the most accurate model to be the ensembled tree. Later, I exported the model and tried to implement the following code:
Mdl = trainedModel_num.ClassificationEnsemble;
pd = plotPartialDependence(Mdl,{'Car','Travel'});
But it says the following:
Error using classreg.learning.classif.FullClassificationModel/plotPartialDependence (line 391)
Not enough input arguments.
Please let me hear your thoughts.
Thanks

Answers (1)

Drew
Drew on 18 Oct 2022
Edited: Drew on 18 Oct 2022
Note, starting in R2022b, Partial Dependence line plots are available within the Classification and Regression Learner apps. For more information, see Interpret Model Using Partial Dependence Plots (for classification) and Interpret Model Using Partial Dependence Plots (for regression). For examples, see Interpret Classifiers Trained in Classification Learner App and Interpret Regression Models Trained in Regression Learner App.
If you want to continue to produce PDP plots at the command line, as indicated by the error message, your plotPartialDependence command does not have enough input arguments. You need to indicate the third argument of an output class Label or Labels. As indicated in the doc page, https://www.mathworks.com/help/stats/regressiontree.plotpartialdependence.html, plotPartialDependence requires three inputs when used with a Classification Model. Quoting from the doc:
plotPartialDependence(ClassificationMdl,Vars,Labels) computes and plots the partial dependence between the predictor variables listed in Vars and the scores for the classes specified in Labels by using the classification model ClassificationMdl, which contains predictor data.
  • If you specify one variable in Vars, the function creates a line plot of the partial dependence against the variable for each class in Labels.
  • If you specify two variables in Vars, the function creates a surface plot of the partial dependence against the two variables. You must specify one class in Labels.
As an example,
t=readtable('fisheriris.csv');
% Then start classificationLearner, build your ensemble of choice, and then
% export the model (with the training data)
% Next, isolate the classreg model
% Mdl = trainedModel_num.ClassificationEnsemble
%
% Now, for demonstration purposes, lets train an ensemble of bagged trees
% at the command line instead of with the app. To see how to do this, you can look
% at the training function produced by the app. Also for simplicity, we will just train on
% all the data (rather than doing a train/validate/test or crossvalidation split of
% the data)
template=templateTree('MaxNumSplits',149,'NumVariablestoSample','all');
Mdl = fitcensemble(t,'Species', ...
'Method','Bag', ...
'NumLearningCycles',30, ...
'Learners',template, ...
'ClassNames', {'setosa'; 'versicolor'; 'virginica'});
% Example line plot PDP.
% Notice the three inputs: model, predictor, and set of output class labels
plotPartialDependence(Mdl,{'PetalWidth'},{'setosa' 'versicolor' 'virginica'});
legend('Location','best');
% Example surface plot PDP:
% Notice the three inputs: model, two predictors, and a single output class label
plotPartialDependence(Mdl,{'PetalWidth' 'PetalLength'},{'virginica'});

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!