what toolbox to include for regression

3 次查看(过去 30 天)
I am running the following code on MATLAB Grader
A=[13 16 19 21 24 26 28]
M=[13 20 23 31 36 42 48]
[r,m,b] =regression(A,M)
It is throwing the following error.
"Undefined function 'regression' for input arguments of type 'double'."
What toolbox I need to include to over come this error?

采纳的回答

Shivani
Shivani 2024-6-11
编辑:Shivani 2024-6-11
The regression function is a part of the Deep Learning Toolbox. The following links can be used to access the associated MATLAB documentation.
However, please note that it is not recommended to use the 'regression' function. Instead, it is recommended to use the 'fitlm' function from the Statistics and Machine Learning Toolbox to fit a linear regression model. Please access the following links for more information:

更多回答(1 个)

Image Analyst
Image Analyst 2024-6-11
For these few data points, and for a case like this where the best fit might simply be a line, you can use the build-in polyfit and polyval functions. Here is some code for you:
A=[13 16 19 21 24 26 28];
M=[13 20 23 31 36 42 48];
plot(A, M, 'b.-', 'MarkerSize', 30); % Plot original data in blue.
grid on;
coefficients1 = polyfit(A, M, 1) % Fit a line.
coefficients1 = 1x2
2.2955 -17.7760
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
coefficients2 = polyfit(A, M, 2) % Fit a quadratic.
coefficients2 = 1x3
0.0422 0.5589 -0.9810
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Place a line along the fitted formula
x = linspace(min(A), max(A), 1000);
% Plot the fitted line.
y1 = polyval(coefficients1, x);
hold on;
plot(x, y1, 'r-', 'LineWidth', 2); % Plot linear fit as a red curve.
% Plot the fitted quadratic.
y2 = polyval(coefficients2, x);
plot(x, y2, 'm-', 'LineWidth', 2); % Plot quadratic fit as a magenta curve.
legend('Original Data', 'Fitted Line', 'Fitted Quadratic', 'Location', 'northwest')
hold off;

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by