1. Use the Generated Function
After training your model in the Regression Learner app, click on "Generate Function" to create a function. This function will take in new data and output predictions based on your model.
2. Prepare Your Data
Load or prepare the dataset you want to use for plotting. Ensure it's in the same format as the data used for training the model.
3. Get Predictions
Use the generated function to get predictions. For example, if your generated function is named trainedModel, you can get predictions as follows:
Ypredicted = trainedModel.predictFcn(Xnew);
4. Create Plotsa. Response Plot
A response plot shows the relationship between the predicted and actual responses.
plot(Yactual, Ypredicted, 'bo');
maxVal = max(max(Yactual), max(Ypredicted));
plot([0, maxVal], [0, maxVal], 'k--');
xlabel('Actual Response');
ylabel('Predicted Response');
b. Predicted vs. Actual Plot
This is similar to the response plot but often includes more detailed analysis (like coloring by groups or adding other plot features).
scatter(Yactual, Ypredicted);
title('Predicted vs Actual Plot');
c. Residuals Plot
Residuals are the difference between the actual and predicted values.
residuals = Yactual - Ypredicted;
plot(Ypredicted, residuals, 'bo');
xlabel('Predicted Response');
5. Customizing Your Plots
You can customize these plots with different MATLAB plotting features, like changing colors, adding grid lines, setting axis limits, etc.
6. Automation
To automate this process, you can write a script or function that includes the above steps. This way, you can easily generate these plots for any new dataset by running the script/function.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.