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
How to predict output values of new data in stepwise regression?
1 次查看(过去 30 天)
显示 更早的评论
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).
采纳的回答
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
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).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model Building and Assessment 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!