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

11 ビュー (過去 30 日間)
Miljan Kovacevic
Miljan Kovacevic 2019 年 5 月 21 日
回答済み: Udit06 2024 年 11 月 11 日 6:21
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 Center および File ExchangeRegression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by