Can't create Partial Dependence Plot
3 views (last 30 days)
Show older comments
Hi,
I am currently working in have 2022a, and I have an App that creates Regression/Classification Models. I am trying to show how the target depends on some generated features, so I want to plot some Partial Dependence graphs, however, I am unable to do this. The Model I have is a RegressionLinear model and looks like this:

If I try and use the command line to run a Partial Dependence Plot, it doesn't obtain any features:

If I try and call this the way that the documentation describes (plotPartialDependence(Mdl,1)), I get this:

Is there anything that I'm doing wrong, it does say that RegressionLinear is allowed for PartialDependence plots, so I'm confused.
Thanks,
James
1 Comment
nick
on 7 Nov 2023
Hi James,
I tried using the 'plotPartialDependence' function at my end on Linear Regression model and it works fine. Kindly share the code files to ensure reproducibility of the error at my end.
Answers (1)
Hitesh
on 4 Apr 2025
Hi James,
'plotPartialDependence' function works as intended in MATLAB R2022a. Kindly refer to the following piece of code as an use case of 'plotPartialDependence' function.
% Load or define your dataset
% X is the matrix of features, and y is the target variable
% For example purposes, let's create some sample data
X = rand(100, 3); % 100 samples, 3 features
y = 2 * X(:,1) + 3 * X(:,2) + 4 * X(:,3) + randn(100, 1);
% Train a linear regression model
Mdl = fitlm(X, y); % Mdl is your trained RegressionLinear model
% Specify the feature index for which you want to plot the Partial Dependence
featureIndex = 1; % Change this to the desired feature index
% Create the Partial Dependence Plot
figure;
plotPartialDependence(Mdl, featureIndex, X);
% Add labels and title for clarity
xlabel('Feature 1');
ylabel('Partial Dependence');
title('Partial Dependence Plot for Feature 1');
Kindly refer to the following MATLAB documentation for better understanding of 'plotPartialDependence' function:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!