GPRegressor#

class GPRegressor(features: str | Iterable[str], target: str, *, kernel: Literal['rbf', 'matern32', 'matern52'] | AbstractKernel = 'matern52', mean_function: Literal['zero', 'constant', 'linear'] | AbstractMeanFunction = 'constant', learned_noise: Literal['constant', 'heteroscedastic'] | None = 'constant', noise_column: str | None = None, schema: Any = None)[source]#

A description of a Gaussian process regression model that summarises nothing: exact with constant or known noise.

It names the dataframe columns that are inputs, the column that is the target, the kernel, the mean function, the noise it learns, optionally a column of known noise, and optionally a schema that checks your data first (see the schema setting). With constant learned noise (the default), known noise, or both, the fit is exact; with heteroscedastic noise it is variational, with an inducing point at every row (see the learned_noise setting). The inputs and the target may be given by position: GPRegressor(["latitude", "altitude"], "temperature"). A mistake in any setting raises ValueError when the model is defined. It never changes: fitting it returns a separate fitted model, and replace returns a new model with other settings.

It gets slow and needs a lot of memory as rows grow, with either noise. When fit is given more rows than skgp.config.size_warning_rows (10,000 unless you change it), it issues one skgp.LargeDataWarning naming SparseGPRegressor, then fits as usual. The limit only decides whether you are warned; it never changes the model fitted.

check(data: NativeDataFrame, *, for_prediction: bool = False, verbose: bool = False) → CheckedData#

Run every data check of this model on data and return it as CheckedData.

Training data (the default) needs the feature and target columns and at least 5 rows. Each input must hold numbers, or dates, or dates and times: a date input, which the model counts in days since 1970-01-01 in UTC (a date and time with no time zone is taken as UTC). A regressor’s target must hold numbers; a classifier’s must hold exactly two different values, of any type. A GPRegressor’s noise_column, if it has one, must hold numbers that are zero or more; rows to predict need it only for a prediction with noise, and it is checked whenever they have it. With for_prediction=True only the feature columns are needed, and any number of rows, and a target column is ignored. Any column that is neither an input, the target nor the column of known noise is ignored. Your schema, if you gave one, runs first; whatever it raises propagates. Raises ValueError, naming the column at fault, when one of skgp’s own checks fails.

fit and predict accept the result without checking it again, on this model or any other of the same task (regression or classification) with the same features, target, schema and column of known noise.

With verbose=True, skgp emits log records through loguru, as fit and predict do: the settings given, which checks ran and whether they passed, and the names of any columns ignored. With the default False it emits nothing.

fit(data: NativeDataFrame | CheckedData, *, iterations: int = 2000, verbose: bool = False) → FittedGPRegressor#

Fit to data, returning a separate fitted model.

data is a Polars, pandas or other dataframe, which is checked first, or a CheckedData from the check of this model or of any regressor with the same features, target, schema and column of known noise, which is not checked again. self is unchanged.

iterations is a whole number above zero. For a GPRegressor, or a SparseGPRegressor without a minibatch_size, it is the most iterations the optimiser may take; it stops sooner once the fit has finished. For a SparseGPRegressor with a minibatch_size, it is exactly the number of iterations run, each on one minibatch.

With verbose=True, skgp emits log records through loguru, each a short message with named fields (in record["extra"]), so you choose where they go. A long fit reports its progress every few seconds, except a SparseGPRegressor with a minibatch_size, which shows GPJax’s progress bar on standard error instead. With the default False it emits nothing.

If a fit on all rows at once does not finish properly (the same condition to_json() reports as finished_properly: false), fit issues one skgp.ConvergenceWarning, a UserWarning, whatever verbose is, and still returns the fitted model, which may be less reliable. Filter or escalate it with the warnings module. The warning says what to check: the scale of your data and whether it is noise-free, and for a fit that used all its iterations without settling, a larger iterations. Fits that finish properly are silent. A SparseGPRegressor with a minibatch_size runs exactly its iterations, and skgp does not judge whether it converged, so it never issues this warning.

replace(**changes: Any) → Self#

A new model like this one with changes made, for example model.replace(kernel="rbf"). This one is unchanged.

The new model is checked as any new model is, so a mistake raises ValueError. A setting you never gave keeps its default unless you change it.

features#

The columns of your dataframe that are the model’s inputs, in order: a list of column names, or a single name for one input. Each column is named once, and the target is not among them.

kernel#

The kind of curve the model expects: a name, or a GPJax kernel.

  • By name: "matern52" (the default) for a smooth curve, "matern32" for a rougher one, or "rbf" for a very smooth one. Each has one length scale per input, learned from the data, starting at that input’s standard deviation.

  • A GPJax kernel, such as gpjax.kernels.RBF() + gpjax.kernels.Periodic(period=52.0), is fitted as you give it. Its values are where the fit starts, and a value held with paramax.non_trainable stays where you put it. A kernel with one length scale keeps one; give one per input, such as lengthscale=jnp.array([1.0, 500.0]), for more.

Every kernel sees the inputs in the units of your columns, so a value that measures distance along an input, such as a length scale or a period, is in those units, both as you give it and as the fit reports it. A date input, an input column of dates or of dates and times, is in days since 1970-01-01, so gpjax.kernels.Periodic(period=365.25) repeats every year. (The length scale of GPJax’s Periodic kernel measures a fraction of the period instead, and has no units.) A regressor’s kernel variance is relative to the target’s variance, so 1 means the curve varies as much as the target does. A kernel’s active_dims are positions in features, counting from 0. Any other value, and active_dims past the last feature, are refused when the model is defined.

learned_noise#

The noise on each observation that the model learns from the data, and how it varies.

  • "constant" (the default): the same at every row, one number learned from the data. With a GPRegressor’s noise_column, it is added to each row’s known noise: the noise variance at a row is its known noise squared plus the learned noise squared.

  • "heteroscedastic": varying with the inputs, as where a measurement gets noisier as it gets larger. The logarithm of the noise variance is a second Gaussian process, the noise process, with a "matern52" kernel of its own, the noise kernel, learned from the data together with the curve. GPJax has no exact fit of this model, so a GPRegressor fits it by variational inference with an inducing point at every row for the curve and for the noise process, as a GPClassifier is fitted, and a SparseGPRegressor with its inducing points for each of the two. It cannot be combined with a noise_column.

  • None: no learned noise; the noise is the known noise in a GPRegressor’s noise_column alone, which must then be given.

A prediction’s spread includes the noise at each row, unless you ask for the curve alone with include_noise=False.

mean_function#

What the curve is far from the training data, where the data says nothing: a name, or a GPJax mean function. Near the data, the curve follows the data whatever the mean function is.

  • "constant" (the default): one number, learned from the data. A regressor’s starts at the target’s average.

  • "zero": zero in the target’s units, held there: for a target that goes back to 0 far from the data, such as a difference from a long-term average.

  • "linear": a number plus a slope along each input, all learned, so that a prediction far from the data keeps rising or falling along each input as the data does. A slope is in the target’s units per unit of its input’s column: per day along a date input. The slope is one value, learned, so a prediction’s spread does not include any doubt about it, which matters more the further from the data you predict.

  • A GPJax mean function, such as gpjax.mean_functions.Constant(15.0), sees the inputs in the units of your columns and gives the curve in the target’s units. Its values are where the fit starts, and a value held with paramax.non_trainable stays where you put it. On a fit on minibatches, each step moves a value by about a twentieth of the target’s standard deviation (of 1 for a classifier), or by about a twentieth of itself if it must be positive and is above 1, so start it near where it belongs: the names start at the target’s average.

With heteroscedastic noise, the mean function is the curve’s; the noise process keeps its own learned constant mean.

A classifier’s curve is the one it turns into probabilities through the probit, so its mean function has no units: far from the data, the probability of the second class goes towards the probit of the mean function there, nearer 0.5 the less the model knows. Any other value is refused when the model is defined.

noise_column: str | None#

The column of your dataframe that holds the known noise on each observation, such as an instrument’s stated error: a standard deviation, in the target’s units, for every row. Zero is allowed; a negative or missing value is refused. The model learns the rest of the noise, as learned_noise says, or none.

It goes with learned_noise "constant" or None. A SparseGPRegressor takes no known noise: GPJax’s sparse fits take the same noise at every row. Rows to predict need the column when the prediction includes noise (include_noise=True, the default), because a new observation has its own known noise; without noise they do not. It is neither an input nor the target. Leave it unset (the default) when no noise is known.

schema = None#

Your own data checker: any object with a .validate(frame) method that raises on bad data. A pandera schema works; skgp does not depend on pandera.

It runs first, inside check (so at fit and predict), on the dataframe exactly as you passed it, in your own dataframe type, because a schema may fix types. skgp’s own checks then always run too and cannot be switched off.

  • If validate returns a dataframe (pandera returns the validated, possibly coerced, frame), skgp’s checks and the model use that returned frame.

  • If it returns None, skgp’s checks use the frame you passed.

  • Whatever it raises propagates unchanged and stops the call.

  • It also sees prediction rows, which have no target column, so it must accept that (in pandera, mark the target column required=False).

  • A CheckedData passed to fit or predict is not validated again.

A value with no callable validate is rejected when the model is defined. The schema is not included in a fitted model’s to_json(). Two models are equal only if their schemas are equal.

settings_not_taken = {}#

Settings another model takes and this one does not, each with the reason, which the refusal gives.

target#

The column of your dataframe that the model learns to predict.