How do I create a cross validated linear regression model with fitlm ?

19 ビュー (過去 30 日間)
Mara
Mara 2017 年 2 月 5 日
コメント済み: Mattias Blomfors 2017 年 9 月 6 日
I would like to know how I can perform cross validation on a fitlm model. All other functions for regression models support KFold as a function object. How does KFold work with fitlm as there is noch function object for cross validation implemented. I also tried crossval on a trained fitlm model which didn't work either. I hope someone can help me with my problem.

回答 (1 件)

Shubham Srivastava
Shubham Srivastava 2017 年 2 月 14 日
You can perform a K-fold cross validation for the 'fitlm' function into K folds using the 'crossval' function. In order to do so, define a predictor function handle which uses 'fitlm' and then pass the predictor function handle to the 'crossval' function.
Mentioned below is a sample code snippet to do so:
% prediction function given training and testing instances
>> fcn = @(Xtr, Ytr, Xte) predict( fitlm(Xtr,Ytr), Xte);
% perform cross-validation, and return average MSE across folds
>> mse = crossval('mse', X, Y,'Predfun',fcn, 'kfold',10);
% compute root mean squared error
>> avrg_rmse = sqrt(mse)
Regards,
Shubham
  2 件のコメント
Mara
Mara 2017 年 2 月 16 日
Thank you for your response! I have another question. When I have a new dataset with which I would like to predict my output using the cross validated trained model. How can I make predictions and calculet the mse then? Is it possible to create a cross validated linear regression model (as model object) like cross validated tree or SVM ?
Mattias Blomfors
Mattias Blomfors 2017 年 9 月 6 日
I share the same question as Mara. How do I use the cross validated trained model to make predictions? Also, how to get the parameters for the linear model?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGaussian Process Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by