フィルターのクリア

How to predict output values of new data in stepwise regression?

4 ビュー (過去 30 日間)
Ajay Goyal
Ajay Goyal 2015 年 12 月 28 日
コメント済み: Ajay Goyal 2015 年 12 月 29 日
Dear Friends, I have generated a stepwise quadratic model using stepwiselm. At start of running the code, I have divided my training and tested data. After training (generating the model) I want to calculated output for tested data. I am trying to use predict command but unable to execute it. Could you please help me (maybe with an example).
  1 件のコメント
Ajay Goyal
Ajay Goyal 2015 年 12 月 29 日
Thank You Proff Brendan for your help. It worked. Yesterday I was doing a silly mistake. Thanks once again for enlighten me from your knowledge

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

採用された回答

Brendan Hamm
Brendan Hamm 2015 年 12 月 28 日
rng('default') % Reproducibility
n = 200; % 200 samples
% Generate some data which is quadratic
x = 4*(rand(n,1)-0.5); % Samples from U([-2 2])
y = 1.2 + 7.8*x -2.6*x.^2 + 5*randn(n,1);
pt = cvpartition(n,'Holdout',0.5); % Create partition
trainX = x(training(pt)); % Get training predictor data
trainY = y(training(pt)); % Get training response data
testX = x(test(pt)); % Get validation predictor data
testY = y(test(pt)); % Get validation response data
% Plot test data:
plot(trainX,trainY,'ko')
% Fit model and predict:
mdl = stepwiselm(trainX,trainY,'y ~ 1','Criterion','BIC','Upper','y~1+x1^5');
predY = predict(mdl,testX);
% Plot predictions against known response
plot(testX,predY,'r*')
hold on
plot(testX,testY,'bo')
  2 件のコメント
Brendan Hamm
Brendan Hamm 2015 年 12 月 28 日
If this is not working you may have made your own function called predict which shadows the method. What is happening when predict is "not working"? Is it an error, and if so what does it say?
Are you perhaps looking at the documentation for a different predict (there are many for different classes).
Ajay Goyal
Ajay Goyal 2015 年 12 月 29 日
Thank You Sir for your help. It worked. Yesterday I was doing a mistake. Thanks for enlighten me from your knowledge

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

その他の回答 (0 件)

カテゴリ

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