필터 지우기
필터 지우기

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 CenterFile Exchange에서 Gaussian Process Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by