uqregressors.bayesian.gaussian_process
This is a compatibility wrapper of the scikit-learn Gaussian Process Regressor such that predictions return intervals rather than means and/or standard deviations.
GPRegressor
A wrapper for scikit-learn's GaussianProcessRegressor with prediction intervals.
This class provides a simplified interface to fit a Gaussian Process (GP) regressor, make predictions with uncertainty intervals, and save/load the model configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the model. |
'GP_Regressor'
|
kernel
|
Kernel
|
Kernel to use for the GP model. |
RBF()
|
alpha
|
float
|
Significance level for the prediction interval. |
0.1
|
gp_kwargs
|
dict
|
Additional keyword arguments for GaussianProcessRegressor. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Name of the model. |
kernel |
Kernel
|
Kernel to use in the GP model. |
alpha |
float
|
Significance level for confidence intervals (e.g., 0.1 for 90% CI). |
gp_kwargs |
dict
|
Additional keyword arguments for the GaussianProcessRegressor. |
model |
GaussianProcessRegressor
|
Fitted scikit-learn GP model. |
Source code in uqregressors\bayesian\gaussian_process.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
fit(X, y)
Fits the GP model to the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
Feature matrix of shape (n_samples, n_features). |
required |
y
|
ndarray
|
Target values of shape (n_samples,). |
required |
Source code in uqregressors\bayesian\gaussian_process.py
40 41 42 43 44 45 46 47 48 49 50 |
|
load(path, device='cpu', load_logs=False)
classmethod
Loads a previously saved GPRegressor from disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[str, Path]
|
Path to the directory containing the saved model. |
required |
device
|
str
|
Unused, included for compatibility. Defaults to "cpu". |
'cpu'
|
load_logs
|
bool
|
Unused, included for compatibility. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
GPRegressor
|
The loaded model instance. |
Source code in uqregressors\bayesian\gaussian_process.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
predict(X)
Predicts the target values with uncertainty estimates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
Feature matrix of shape (n_samples, n_features). |
required |
Returns:
Type | Description |
---|---|
Union[Tuple[ndarray, ndarray, ndarray], Tuple[Tensor, Tensor, Tensor]]
|
Tuple containing: mean predictions, lower bound of the prediction interval, upper bound of the prediction interval. |
Note
If requires_grad
is False, all returned arrays are NumPy arrays.
Otherwise, they are PyTorch tensors with gradients.
Source code in uqregressors\bayesian\gaussian_process.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
save(path)
Saves the model and its configuration to disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[str, Path]
|
Directory where model and config will be saved. |
required |
Source code in uqregressors\bayesian\gaussian_process.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|