Example code for trainedmodel.predictfcn

32 views (last 30 days)
Jeremy Grata
Jeremy Grata on 2 Dec 2024 at 20:21
Edited: Jeremy Grata on 3 Dec 2024 at 15:11
Is there a way to have matlab generate a script showing the steps the predictfcn of a trained regression model uses to generate predictions? The steps executed when yfit=trainedmodel.predictfcn(x)is called? PCA steps, if included in the model, should be shown also.
For example, a GPR Rational Quadratic model:
trainedModelGPR_RQ.RegressionGP=
RegressionGP
PredictorNames: {1×58 cell}
ResponseName: 'Y'
CategoricalPredictors: []
ResponseTransform: 'none'
NumObservations: 1487
KernelFunction: 'RationalQuadratic'
KernelInformation: [1×1 struct]
BasisFunction: 'Constant'
Beta: 74.872929476342
Sigma: 0.276734525120447
PredictorLocation: [58×1 double]
PredictorScale: [58×1 double]
Alpha: [1487×1 double]
ActiveSetVectors: [1487×58 double]
PredictMethod: 'Exact'
ActiveSetSize: 1487
FitMethod: 'Exact'
ActiveSetMethod: 'Random'
IsActiveSetVector: [1487×1 logical]
LogLikelihood: -6383.13344737248
ActiveSetHistory: []
BCDInformation: []
with
trainedModelGPR_RQ.RegressionGP.KernelInformation.KernelParameters =
1.83516539103131
0.288843383795902
32.3071857452573
where
trainedModelGPR_RQ.RegressionGP.KernelInformation.KernelParameterNames =
3×1 cell array
{'SigmaL' }
{'AlphaRQ'}
{'SigmaF' }
For a new set of predictors, Xnew having a size of m x 58, how are the predictions for Xnew computed (manually, ie not using predict) given informaiton in the model the above? Looking for something in the form of:
ypred=A*f(Xnew)-B, where A and B are some combination of values stored in the trained model and f may be a PCA step on Xnew, if part of the model.
For GPR Rational Quadratic, ignoring any PCA, what are
A and B?

Answers (0)

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!