Kernel parameter values of a Gaussian process regression (GPR) model using regression learner

조회 수: 11 (최근 30일)
Dear friends,
I trained Gaussin proces regression model using Regression learner.
I used 5 fold cross validation.
When we use cross validation we actually get 5-fold cross validation and five different models, however, when I enter the kernel information field, I see the kernel parameters for just one model.
Can anyone explain this?
Thanks
function [trainedModel, validationRMSE] = trainRegressionModel(trainingData)
% [trainedModel, validationRMSE] = trainRegressionModel(trainingData)
% returns a trained regression model and its RMSE. This code recreates the
% model trained in Regression Learner app. Use the generated code to
% automate training the same model with new data, or to learn how to
% programmatically train models.
%
% Input:
% trainingData: a matrix with the same number of rows and data type as
% imported into the app.
%
% Output:
% trainedModel: a struct containing the trained regression model. The
% struct contains various fields with information about the trained
% model.
%
% trainedModel.predictFcn: a function to make predictions on new data.
%
% validationRMSE: a double containing the RMSE. In the app, the
% History list displays the RMSE for each model.
%
% Use the code to train the model with new data. To retrain your model,
% call the function from the command line with your original data or new
% data as the input argument trainingData.
%
% For example, to retrain a regression model trained with the original data
% set T, enter:
% [trainedModel, validationRMSE] = trainRegressionModel(T)
%
% To make predictions with the returned 'trainedModel' on new data T2, use
% yfit = trainedModel.predictFcn(T2)
%
% T2 must be a matrix containing only the predictor rows used for training.
% For details, enter:
% trainedModel.HowToPredict
% Auto-generated by MATLAB on 21-May-2019 09:21:35
% Extract predictors and response
% This code processes the data into the right shape for training the
% model.
% Convert input to table
inputTable = array2table(trainingData', 'VariableNames', {'row_1', 'row_2', 'row_3', 'row_4', 'row_5', 'row_6', 'row_7', 'row_8', 'row_9', 'row_10'});
predictorNames = {'row_1', 'row_2', 'row_3', 'row_4', 'row_5', 'row_6', 'row_7', 'row_8', 'row_9'};
predictors = inputTable(:, predictorNames);
response = inputTable.row_10;
isCategoricalPredictor = [false, false, false, false, false, false, false, false, false];
% Train a regression model
% This code specifies all the model options and trains the model.
regressionGP = fitrgp(...
predictors, ...
response, ...
'BasisFunction', 'constant', ...
'KernelFunction', 'matern52', ...
'Standardize', true);
% Create the result struct with predict function
predictorExtractionFcn = @(x) array2table(x', 'VariableNames', predictorNames);
gpPredictFcn = @(x) predict(regressionGP, x);
trainedModel.predictFcn = @(x) gpPredictFcn(predictorExtractionFcn(x));
% Add additional fields to the result struct
trainedModel.RegressionGP = regressionGP;
trainedModel.About = 'This struct is a trained model exported from Regression Learner R2018a.';
trainedModel.HowToPredict = sprintf('To make predictions on a new predictor row matrix, X, use: \n yfit = c.predictFcn(X) \nreplacing ''c'' with the name of the variable that is this struct, e.g. ''trainedModel''. \n \nX must contain exactly 9 rows because this model was trained using 9 predictors. \nX must contain only predictor rows in exactly the same order and format as your training \ndata. Do not include the response row or any rows you did not import into the app. \n \nFor more information, see <a href="matlab:helpview(fullfile(docroot, ''stats'', ''stats.map''), ''appregression_exportmodeltoworkspace'')">How to predict using an exported model</a>.');
% Extract predictors and response
% This code processes the data into the right shape for training the
% model.
% Convert input to table
inputTable = array2table(trainingData', 'VariableNames', {'row_1', 'row_2', 'row_3', 'row_4', 'row_5', 'row_6', 'row_7', 'row_8', 'row_9', 'row_10'});
predictorNames = {'row_1', 'row_2', 'row_3', 'row_4', 'row_5', 'row_6', 'row_7', 'row_8', 'row_9'};
predictors = inputTable(:, predictorNames);
response = inputTable.row_10;
isCategoricalPredictor = [false, false, false, false, false, false, false, false, false];
% Perform cross-validation
partitionedModel = crossval(trainedModel.RegressionGP, 'KFold', 5);
% Compute validation predictions
validationPredictions = kfoldPredict(partitionedModel);
% Compute validation RMSE
validationRMSE = sqrt(kfoldLoss(partitionedModel, 'LossFun', 'mse'));
  댓글 수: 1
Miljan Kovacevic
Miljan Kovacevic 2019년 5월 21일
I get for
trainedModel.RegressionGP.KernelInformation
KernelParameters [0.6057 208.0861]
and for partitioned model
[0.7626 207.2902]
[0.6669 211.6438]
[0.6185 222.9631]
[0.6041 218.8468]
[0.5874 214.5818/]

댓글을 달려면 로그인하십시오.

답변 (1개)

Udit06
Udit06 2024년 11월 11일 6:21
Hi Miljan,
You are getting the kernel parameters for only one model for "trainedModel.RegressionGP.KernelInformation" since the function "trainRegressionModel" has the following statement:
regressionGP = fitrgp(predictors, response, 'BasisFunction', 'constant', 'KernelFunction', 'matern52', 'Standardize', true);
The "fitrgp" function used above returns only one model and the kernel information for that model is shown to you.
Please refer to the following MathWorks documentation to understand more about the "fitrgp" function.
I hope this helps.

카테고리

Help CenterFile Exchange에서 Regression에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by