How to develop "a model" from a given m-file of regression analysis?

3 views (last 30 days)
With the help of the attached code I need to develop a model for the price variation based on a combined (linear) dependence on model year such as mileage, plot the result, and develop a corresponding R2 value.
But what does this mean? Does it mean to get a function, where the price is the function f(x) and mileage and model year are parameters in the form of f(x)=ax+b ?
If so, how is that done? I can only find B, L and c in the output.
Anhy suggestions welcomed.
Thanks!

Accepted Answer

Star Strider
Star Strider on 29 Feb 2024
If your data are the same as in your earlier post, you can get all that information from the Curve Fitting Toolbox result.
That call would be:
fordfocusfit = fit(num{:,[1 2]}, num{:,3}, 'poly11') % The ‘poly11’ Model Does A Linear Surface Fit In Each Independent Variable
figure
plot(fordfocusfit, num{:,[1 2]}, num{:,3})
You can of course change the model from 'poly11' to whatever you want that works with 3-dimensional data (two independent variables and one dependent variable in this instance, if the data are the same as previously).
If you return a handle to the plot, you can use it to change the appearance (marker, colour, etc.).
  5 Comments
Sergio
Sergio on 29 Feb 2024
Edited: Sergio on 29 Feb 2024
@Star Strider did you get an R^2 value with your code? I got one with:
mdl = fitlm(A,B)
Star Strider
Star Strider on 29 Feb 2024
The fitlm call will certainly work. I generally use it because I do not have the Curve Fitting Toolbox, so I only use that in MATLAB Answers posts, since everything is available here.
The Curve Fitting Toolbox requires a separate ‘goodness-of-fit’ output:
[fordfocusfit,GOF] = fit(num(:,[1 2]), num(:,3), 'poly11') % The ‘poly11’ Model Does A Linear Surface Fit In Each Independent Variable
The ‘GOF’ output then has the , adjusted , and other statistics.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 29 Feb 2024
What I would do is to use the Regression Learner app on the Apps tab of the tool ribbon. It's in the Statistics and Machine Learning Toolbox.
Put in your inputs into a table called predictors, and your "response" variable would be the price vector. Then tell it to use all models to do a regression. Look at the errors and choose the model with the lowest errors. Then click the Export button to save the model into a .mat file. The mat file will contain a string that tells you how to apply the model to obtain an estimated price given a set of predictor values.
Attach your workbook if you need more help.
  5 Comments
Image Analyst
Image Analyst on 29 Feb 2024
Slightly better than that : 0.76
That's on the validation data (not used in training). It should be higher if you included the training data of course, but that's not really fair, especially if you're using it on new data, so the r squared on the validation data is what's fair to use.

Sign in to comment.

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!