GaussianProcessRegressionCrossValidation¶
- class GaussianProcessRegressionCrossValidation(*args)¶
Validate a Gaussian Process Regression surrogate model.
Warning
This class is experimental and likely to be modified in future releases. To use it, import the
openturns.experimentalsubmodule.- Parameters:
- result
GaussianProcessRegressionResult A Gaussian Process Regression result.
- splitter
SplitterImplementation, optional The cross-validation method. For now, only the default
LeaveOneOutSplittercan be used.
- result
Methods
Accessor to the mean squared error.
Compute the R2 score.
Plot a model vs metamodel graph for visual validation.
Accessor to the object's name.
Result accessor.
Get the Leave-One-Out prediction standard deviations
Accessor to the output predictions from the metamodel.
getName()Accessor to the object's name.
Accessor to the output sample.
getResidualDistribution([smooth])Compute the non parametric distribution of the residual sample.
Compute the residual sample.
Get the cross-validation method.
hasName()Test if the object is named.
setName(name)Accessor to the object's name.
Notes
A GaussianProcessRegressionCrossValidation object is used for the validation of a Gaussian Process Regression. It is based on the fast (analytical) leave-one-out cross-validation method presented in [ginsbourger2025] (Equation 23).
Note that this method relies on linear algebra, and therefore uses the covariance model parameters fitted on the whole data set. It is therefore not strictly equivalent to the naive cross-validation method, which consists in re-fitting the Gaussian Process Regression model on each training subset.
Examples
Create a Gaussian Process Regression surroagate for the Ishigami function.
>>> import openturns as ot >>> from openturns.experimental import GaussianProcessRegressionCrossValidation >>> from openturns.usecases import ishigami_function >>> im = ishigami_function.IshigamiModel() >>> sampleSize = 500 >>> inputTrain = im.distribution.getSample(sampleSize) >>> outputTrain = im.model(inputTrain) >>> covariance_kernel = ot.SquaredExponential(inputTrain.getDimension()) >>> basis = ot.ConstantBasisFactory(inputTrain.getDimension()).build() >>> gpf = ot.GaussianProcessFitter( ... inputTrain, outputTrain, covariance_kernel, basis ... ) >>> gpf.run() >>> gpf_result = gpf.getResult() >>> gpr = ot.GaussianProcessRegression(gpf_result) >>> gpr.run() >>> gpr_result = gpr.getResult()
Validate the Gaussian Process Regression surrogate model using leave-one-out cross-validation.
>>> validation = GaussianProcessRegressionCrossValidation(gpr_result) >>> r2Score = validation.computeR2Score() >>> print('R2 = ', r2Score[0]) R2 = 0.99...
Draw the validation graph.
>>> graph = validation.drawValidation()
- __init__(*args)¶
- computeMeanSquaredError()¶
Accessor to the mean squared error.
- Returns:
- meanSquaredError
Point The mean squared error of each marginal output dimension.
- meanSquaredError
Notes
The sample mean squared error is:
where
is the sample size,
is the metamodel,
is the input experimental design and
is the output of the model.
If the output is multi-dimensional, the same calculations are repeated separately for each output marginal
for
where
is the output dimension.
- computeR2Score()¶
Compute the R2 score.
- Returns:
- r2Score
Point The coefficient of determination R2
- r2Score
Notes
The coefficient of determination
is the fraction of the variance of the output explained by the metamodel. It is defined as:
where
is the fraction of unexplained variance:
where
is the output of the physical model
,
is the variance of the output and
is the mean squared error of the metamodel:
The sample
is:
where
is the sample size,
is the metamodel,
is the input experimental design,
is the output of the model and
is the sample variance of the output:
where
is the output sample mean:
- drawValidation()¶
Plot a model vs metamodel graph for visual validation.
- Returns:
- graph
GridLayout The visual validation graph.
- graph
Notes
The plot presents the metamodel predictions depending on the model observations. If the points are close to the diagonal line of the plot, then the metamodel validation is satisfactory. Points which are far away from the diagonal represent outputs for which the metamodel is not accurate.
If the output is multi-dimensional, the graph has 1 row and
columns, where
is the output dimension.
- getClassName()¶
Accessor to the object’s name.
- Returns:
- class_namestr
The object class name (object.__class__.__name__).
- getGaussianProcessRegressionResult()¶
Result accessor.
- Returns:
- result
GaussianProcessRegressionResult The result provided.
- result
- getLeaveOneOutStandardDeviations()¶
Get the Leave-One-Out prediction standard deviations
- Returns:
- leaveOneOutStandardDeviations
Point The Leave-One-Out prediction standard deviation for every point left out of the output sample.
- leaveOneOutStandardDeviations
Notes
For every point in the training output sample, the Leave-One-Out prediction for Gaussian Process Regression is assumed to follow a normal distribution with zero mean by the underlying Gaussian Process model. This method returns the standard deviation of this normal distribution.
- getMetamodelPredictions()¶
Accessor to the output predictions from the metamodel.
- Returns:
- outputMetamodelSample
Sample Output sample of the metamodel.
- outputMetamodelSample
- getName()¶
Accessor to the object’s name.
- Returns:
- namestr
The name of the object.
- getOutputSample()¶
Accessor to the output sample.
- Returns:
- outputSample
Sample Output sample of a model evaluated apart.
- outputSample
- getResidualDistribution(smooth=True)¶
Compute the non parametric distribution of the residual sample.
- Parameters:
- smoothbool
Tells if distribution is smooth (true) or not. Default argument is true.
- Returns:
- residualDistribution
Distribution The residual distribution.
- residualDistribution
Notes
The residual distribution is built thanks to
KernelSmoothingif smooth argument is true. Otherwise, an histogram distribution is returned, thanks toHistogramFactory.
- getResidualSample()¶
Compute the residual sample.
- Returns:
- residual
Sample The residual sample.
- residual
Notes
The residual sample is given by :
for
where
is the sample size,
is the model observation,
is the metamodel and
is the
-th input observation.
If the output is multi-dimensional, the residual sample has dimension
, where
is the output dimension.
- getSplitter()¶
Get the cross-validation method.
- Returns:
- splitter
SplitterImplementation The cross-validation method.
- splitter
- hasName()¶
Test if the object is named.
- Returns:
- hasNamebool
True if the name is not empty.
- setName(name)¶
Accessor to the object’s name.
- Parameters:
- namestr
The name of the object.
OpenTURNS