Why fitlm function is giving wierd results?
Show older comments
I am using following code
% PCA
[coeff, score, ~, ~, explained] = pca(X);
X_pca = score(:, 1:10);
% Split data
cv = cvpartition(size(X_pca, 1), 'HoldOut', 0.2);
idxTrain = training(cv);
idxTest = test(cv);
X_train = X_pca(idxTrain, :);
X_test = X_pca(idxTest, :);
Y_train = Y(idxTrain);
Y_test = Y(idxTest);
reg = fitlm(X_train, Y_train);
However, the rusults fitlm are coming wierd. Please suggest me how to get correct results.
Deva
7 Comments
John D'Errico
on 13 Apr 2024
@Devendra - when you edit your question away, you make the answer meaningless, and no longer having any context. That hurts the site, as the answer no longer has any value. You insult the person who wasted their time helping you. And it reduces the chances that others (and certainly that person) will be willing to help you in the future.
Manikanta Aditya
on 13 Apr 2024
As @John D'Errico mentioned, Even if you got your issue resolved, there is no loss for keeping the question as it is without editing, as if someone else faces similar issue they will have reference check the particular answer, deleting or editing them will make no sense to them, so consider not to edit or delete the question after posting. Thanks.
Devendra
on 14 Apr 2024
Manikanta Aditya
on 14 Apr 2024
You can use the 'predict' function in MATLAB to predict the dependent variable for the next year using the regression coefficients from your model. You just need to ensure that the independent variables for the next year are in the same format as your scoreTest95 data.
% Train the model
mdl = fitlm(scoreTrain95, Y_train, 'y ~ x1*x2*x3-x1:x2:x3');
% Obtain the independent variable data for the next year
nextYearData = [...];
% Create a dataset array from nextYearData
nextYearDataset = array2table(nextYearData, 'VariableNames', {'x1', 'x2', 'x3'});
% Predict the dependent variable for the next year
nextYearPredictions = predict(mdl, nextYearDataset);
Hope it helps.
Devendra
on 14 Apr 2024
Manikanta Aditya
on 14 Apr 2024
Thank you! Good to know.
Accepted Answer
More Answers (0)
Categories
Find more on Resampling Techniques in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!