FittedGPClassifier#

class FittedGPClassifier[source]#

A model fitted to data by a GPClassifier or a SparseGPClassifier. It never changes.

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

Run every data check on rows to predict and return them as CheckedData.

The same as check(data, for_prediction=True) on the model that was fitted, and also that each date input of the training data is a date input here, and every other input holds numbers: the feature columns are needed, the target is not, and any number of rows will do. Pass the result to predict, which does not check it again, apart from the date inputs. With verbose=True, skgp logs what the checks did.

predict(data: NativeDataFrame | CheckedData, *, suffix: str = '', batch_size: int = 1_000, verbose: bool = False) → ClassPrediction[source]#

What the model expects at each row of data, as a ClassPrediction: the probability of each class, and the more likely one.

data needs the feature columns but no target. It is a dataframe, which is checked first, or a CheckedData from the check of this model or of any classifier with the same features, target and schema (for training or prediction data), which is not checked again. Columns the model does not use are ignored, and a verbose log record names them. Every column of data comes back in ClassPrediction.to_frame(), in the same kind of dataframe as data; a missing input column raises.

  • suffix: text added to the names of the columns skgp adds (the probability of each class and most_likely_class), for rows that already have a column with one of those names. Empty by default.

  • batch_size: how many rows are predicted at a time, a whole number above zero. Memory grows with it; the answers do not change.

A row far from the training data, where the model knows little, gets probabilities nearer 0.5. No probability is below 0.001 or above 0.999.

With verbose=True, skgp emits log records through loguru, each a short message with named fields (in record["extra"]). With the default False it emits nothing.

score(data: NativeDataFrame | CheckedData, *, scoring: str | Callable[[...], float] | Iterable[str | Callable[[...], float]] | Mapping[str, str | Callable[[...], float]] = 'neg_brier_score') → Score[source]#

How well the model predicts the known classes of held-out data, as a Score: the value of each scorer, where higher is better.

data holds the feature columns and the target, a class the model knows at every row. It is a dataframe, which is checked first, or a CheckedData of this model, which is not checked again but for the target. Other columns are ignored, as in predict.

scoring takes what cross_val_score(scoring=...) takes: a scikit-learn scorer’s name, such as "accuracy", "neg_log_loss", "roc_auc" or "f1" (sklearn.metrics.get_scorer_names() lists them), a scorer itself, a list of either, or a dict from the name each value gets to its scorer. The default, "neg_brier_score", is the Brier loss with its sign flipped: the mean squared difference between the probability of classes[1] and 1 where it is the class, 0 where it is not, from 0 (perfect) to 1, no unit. The scorers see the classes coded 0 and 1, as the model coded them, so classes[1] is the positive class of f1 and the like, whatever the classes are. An unknown name raises scikit-learn’s ValueError.

to_json() → str[source]#

A read-only JSON description of the fitted model, for inspection and audit.

It cannot be used to rebuild the model. The output is always strict JSON: any number that is not finite (NaN or infinite, for example the final_objective of a fit that diverged) is written as null, so it round-trips through any standard JSON parser. The keys are:

  • skgp_version: the version of skgp that fitted the model. A model saved with pickle and loaded elsewhere keeps the version that fitted it, which may differ from the installed one.

  • training_rows: how many rows of data the model was fitted to.

  • setup: what you asked for. features (the input columns, in order), date_features (only when there are date inputs: each of them with its unit, "days since 1970-01-01"), target (the target column), kernel: its name, or for a GPJax kernel its class, with a sum or product of kernels written out, such as "RBF + Periodic", and mean_function: its name, or for a GPJax mean function its class, written out as a kernel’s is.

  • classes: the two values of the target column, the one coded 0 first.

  • learned: what fitting found out about the data.

    • kernel: every value of the fitted kernel, by its place in the kernel, as GPJax names it: lengthscale and variance for a kernel by name, and kernels[1].period for the period of the second kernel of a sum. A value with one number per input is given for each input column, by its name; a single number for all of them is one number. A length scale is how far you have to move along an input, in the column’s own units, before the probabilities change appreciably: larger means smoother along it. A period is in the column’s units too; the length scale of a Periodic kernel measures a fraction of the period instead, and has no units. The variance is that of the curve whose probit is the probability of the second class, which has no units: larger means the probabilities can come nearer 0 and 1.

    • mean_function: only for a mean function with values, so not for "zero". Its values are on the scale of the same curve, with no units: constant for "constant"; for "linear", intercept, the curve where every input is 0, and slope, for each input column, by its name, how much the curve rises per unit of the column; for a GPJax mean function, every value of it, by its place in it, as for kernel.

  • fitting: how the search for the learned values ended.

    • finished_properly: only for a fit on all rows. True if the fit finished, false if it did not, in which case the learned values may be poor. It is judged from where the fit ended, not from what the optimiser reported: true means further steps would no longer change the fit by much, whether the optimiser stopped by itself or used all its iterations. A SparseGPClassifier fitted on minibatches runs every one of its iterations, and skgp does not judge whether it converged.

    • iterations: how many iterations the fit took: at most the iterations given to fit for a fit on all rows, and exactly that many for a fit on minibatches, where an iteration looks at one minibatch.

    • final_objective: how well the fit explains the classes at the end, as a number where lower is better: the negative of a lower bound on the log marginal likelihood. For a fit on minibatches it is scaled to all the rows and averaged over the iterations of the last pass, so it is noisy. It is useful for comparing fits of the same data and settings.

    • stop_reason: only for a fit on all rows. Why the fit stopped, as a sentence in plain words, the same one the ConvergenceWarning gives.

  • model: only for a model made by a SparseGPClassifier.

    • class: the name of the description that made the model, "SparseGPClassifier".

    • num_inducing: how many inducing points the fit used (never more than the number of rows).

    • minibatch_size: the minibatch size, or null for the fit on all rows at once.

    • random_state: the whole number that seeded the fit.

classes: tuple[Any, Any]#

The two values of the target column: the one coded 0 first, then the one coded 1.

property gpjax_model: Any#

The underlying fitted GPJax model, for cases skgp does not cover.

See docs/advanced.md.

model: GPClassifier | SparseGPClassifier#

The model description that was fitted, with every setting it was fitted with.