- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
How can I automatically translate the graphs I obtained through the Regression Learner app into Matlab code automatically??
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Hassaan
2024-1-11
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);
xlabel('Actual');
ylabel('Predicted');
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');
ylabel('Residuals');
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
Feel free to contact me.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!