Prediction#

class Prediction[source]#

What a fitted regressor expects at each row you asked about, in your original units.

By default it is for a new observation, so the spread includes measurement noise. Made with predict(..., include_noise=False) it is for the underlying curve without the noise: the same mean, with a smaller spread. includes_noise says which, and so does its printed form.

The model’s expectation is one joint normal distribution over all rows: mean(), std() and interval() read its per-row values, and covariance() gives how the rows move together. to_frame() puts the predictions next to your rows, and printing a prediction shows that table.

Two predictions are equal only if they are the same object.

covariance() → ndarray[source]#

How the predictions for the rows move together: an n-by-n numpy array, for n rows.

Row i and column j hold the covariance between rows i and j, in the target’s units squared, in the order of the rows passed to predict. Its diagonal is std() ** 2. Like std(), it includes measurement noise only when includes_noise is True: the noise of each row is its own, so it adds to the diagonal only.

This builds the whole matrix, so memory and time grow with the square of the number of rows (20,000 rows take about 3 GB). mean(), std() and interval() do not build it.

interval(level: float = 0.95) → Any[source]#

Lower and upper bounds that each row falls between with probability level.

Only the lower and upper columns (with your suffix, if you gave one), one row per row passed to predict, in the dataframe type passed to predict. The bounds are for a new observation when includes_noise is True, and for the underlying curve when it is False.

mean() → ndarray[source]#

The predicted mean of each row, in the target’s units, as a numpy array.

It is the same whether or not the prediction includes measurement noise.

sample(n_samples: int = 1, random_state: int = 0) → ndarray[source]#

Random samples of what the model expects, in the target’s units: a numpy array of n rows by n_samples columns, for n rows, the shape scikit-learn’s sample_y gives (its numbers for the same seed differ, as its random number generator does).

Each column is one sample: a value at every row, chosen at random from the joint normal distribution over all the rows (mean() and covariance()), so that the rows hang together as the model expects; nearby rows get similar values. A sample includes measurement noise when includes_noise is True, so it is one possible set of new observations, and is one possible underlying curve when it is False. With heteroscedastic noise the noise at a row is not quite normal, so there the samples of new observations are a normal approximation with the right mean and covariance.

n_samples is a whole number above zero, 1 by default. random_state is a whole number from 0 to 9,223,372,036,854,775,807, 0 by default, as in scikit-learn: the same prediction and random_state give the same samples. It builds the covariance, so memory and time grow with the square of the number of rows.

std() → ndarray[source]#

The predicted standard deviation of each row, in the target’s units, as a numpy array.

It includes measurement noise when includes_noise is True, and is the spread of the underlying curve alone when it is False.

to_frame(interval: float | None = None) → Any[source]#

Your rows, every column you passed, followed by mean and std columns.

It is the dataframe type passed to predict, with the same rows in the same order. Give interval a level between 0 and 1, such as 0.95, to also add lower and upper columns: the bounds interval(level) gives.

If you passed suffix to predict, it is added to the name of every column skgp adds (mean_predicted for suffix="_predicted"). If one of your columns already has the name of a column skgp would add, this raises ValueError naming it; pass a suffix to predict to avoid the clash. mean(), std(), interval() and covariance() are not affected.

includes_noise: bool#

True for a new observation, measurement noise included; False for the underlying curve without it.

suffix: str#

The text added to the names of the columns skgp adds: what you passed to predict as suffix, empty by default.