Azzera filtri
Azzera filtri

How can I automatically translate the graphs I obtained through the Regression Learner app into Matlab code automatically??

2 visualizzazioni (ultimi 30 giorni)
Clicking on Generate function (on export Tab), it generates me a function but that does not create any plot. I just want the plot for example Response plot, predicted Vs actual plot of validation data, residuals plot... Who can help me?

Risposta accettata

Hassaan il 11 Gen 2024
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:
% Assuming Xnew is your new dataset
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');
hold on;
maxVal = max(max(Yactual), max(Ypredicted));
plot([0, maxVal], [0, maxVal], 'k--'); % Adding a 45-degree line for reference
xlabel('Actual Response');
ylabel('Predicted Response');
title('Response Plot');
hold off;
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');
grid on;
c. Residuals Plot
Residuals are the difference between the actual and predicted values.
residuals = Yactual - Ypredicted;
plot(Ypredicted, residuals, 'bo');
xlabel('Predicted Response');
title('Residuals Plot');
hline = refline([0 0]);
hline.Color = 'r';
grid on;
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.

Più risposte (1)

Giuseppe Zumbo
Giuseppe Zumbo il 24 Gen 2024
@Muhammad Hassaan ShahHi Muhammad , may we exchange a contact so I can contact directly? I need some help about it. Thanks in advance.




Community Treasure Hunt

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

Start Hunting!

Translated by