AIC values for a OGPR model trained in the Regression Learner App

조회 수: 1 (최근 30일)
lauzof
lauzof 2024년 5월 31일
편집: Shantanu Dixit 2024년 8월 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

답변 (1개)

Shantanu Dixit
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:
  1. Load the models and data: Load the trained models (TrainedRegressionModel.mat) and some test data against which the models can be evaluted.
  2. 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.
  3. Calculate AIC: Use the likelihood and number of parameters (k) to compute AIC as 2k – 2(log-likelihood)
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:

카테고리

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