- Load the models and data: Load the trained models (TrainedRegressionModel.mat) and some test data against which the models can be evaluted.
- Compute the log-likelihood: Use the predictions from the model (in this case predictFcn) and the ground truth values to calculate the log-likelihood for each model.
- Calculate AIC: Use the likelihood and number of parameters (k) to compute AIC as 2k – 2(log-likelihood)
AIC values for a OGPR model trained in the Regression Learner App
1 次查看(过去 30 天)
显示 更早的评论
Hello!
I'd like to establish an objective criteria for selecting a model trained using the Regression Learner app, especially when several models exhibit similar R2 and RMSE values in the prediction. Could you help me, please, to write a code to estimate the AIC from an exported model?
I'm attaching two exported models for comparison.
I'd really appreciate your help with this!
best,
Laura
0 个评论
回答(1 个)
Shantanu Dixit
2024-8-30
编辑:Shantanu Dixit
2024-8-30
Hi Laura, AIC (Akaike Information Criterion) can be used to evaluate and rank different models based on their performance for a given dataset. Here's how you can calculate AIC for the trained models:
Refer to the example code below for calculating AIC for a model
modelFile = 'TrainedRegressionModel.mat';
loadedData = load(modelFile);
trainedModel = loadedData.trainedModel;
T = yourTestData;
predictedY = trainedModel.predictFcn(T);
actualY = T.target; %% Assuming target contains the actual values
n = length(actualY);
residuals = actualY - predictedY;
sigma2 = var(residuals);
logLikelihood = -n/2 * log(2*pi) - n/2 * log(sigma2) - sum(residuals.^2) / (2*sigma2);
numPredictors = width(T)-1; %% excluding the response variable
k = numPredictors + 1;
AIC = 2*k - 2*logLikelihood;
Refer to following documentation for detailed instructions on making predictions using models trained in Regression Learner App:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gaussian Process Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!