Categories &

Functions List

Function Reference: fitrgp

statistics: Mdl = fitrgp (X, Y)

statistics: Mdl = fitrgp (Tbl, ResponseVarName)

statistics: Mdl = fitrgp (Tbl, formula)

statistics: Mdl = fitrgp (Tbl, Y)

statistics: Mdl = fitrgp (…, name, value)

Fit a Gaussian process regression model.

Mdl = fitrgp (X, Y) returns a RegressionGP object fitted to the predictor data X and the continuous response Y, where X is an NxP numeric matrix and Y an Nx1 numeric vector with as many rows as X.

Mdl = fitrgp (…, name, value) passes the given Name-Value pairs to the model. They are documented under RegressionGP, and the ones most often wanted are 'KernelFunction', 'BasisFunction', 'Standardize', 'Sigma' and 'FitMethod'.

When any of 'CrossVal', 'KFold', 'Holdout', 'Leaveout' or 'CVPartition' is given, a cross validated model is returned instead, as a RegressionPartitionedModel. Only one of them may be given at a time.

See also: RegressionGP, CompactRegressionGP, RegressionPartitionedModel

Source Code: fitrgp

Fit a Gaussian process to a noisy sine and predict on a fine grid.

 x = linspace (0, 2*pi, 30)';
 y = sin (x) + 0.1 * cos (7*x);
 Mdl = fitrgp (x, y)
Mdl =

  RegressionGP

             ResponseName: 'Y'
          NumObservations: 30
            NumPredictors: 1
           KernelFunction: 'SquaredExponential'
            BasisFunction: 'Constant'
                FitMethod: 'Exact'
            PredictMethod: 'Exact'
                    Sigma: 0.0785048
            LogLikelihood: 17.7617
 xq = linspace (0, 2*pi, 5)';
 [yq, ysd] = predict (Mdl, xq)
yq =

   5.8489e-02
   9.9188e-01
   2.6736e-03
  -1.0015e+00
   2.3645e-02

ysd =

   0.098184
   0.084407
   0.084101
   0.084407
   0.098184

Fit from a table, and predict on one

 load fisheriris
 T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ...
            'VariableNames', {'SW', 'PL', 'PW', 'SL'});

A column holding levels is a categorical predictor without being named one

 T.Wide = categorical (meas(:,2) > 3, [false true], {'narrow', 'wide'});

The response is named by its column, and everything else is a predictor

 Mdl = fitrgp (T, 'SL');
 Mdl.PredictorNames
ans =
  1x4 cell array

    {'SW'}    {'PL'}    {'PW'}    {'Wide'}
 Mdl.ResponseName
ans = SL
 Mdl.CategoricalPredictors
ans = 4

A model formula names them instead, holding main effects only

 Mdl2 = fitrgp (T, 'SL ~ PL + Wide');
 Mdl2.PredictorNames
ans =
  1x2 cell array

    {'PL'}    {'Wide'}

predict reads a table by the names the model was fitted on, so the columns may come in any order

 yFit = predict (Mdl, T(1:5, [5, 4, 3, 2, 1]));
 yFit'
ans =

   5.0507   4.6724   4.8432   4.8894   5.1046