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?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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).
Réponse acceptée
Brendan Hamm
le 28 Déc 2015
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 commentaires
Brendan Hamm
le 28 Déc 2015
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).
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Model Building and Assessment dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!