Skip to content

Models

base

Model

Bases: Transformation

predict abstractmethod

predict(X: pd.DataFrame) -> pd.Series | pd.DataFrame

Predictions for exclusively out-of-sample data, the model has never seen before.

predict_in_sample abstractmethod

predict_in_sample(X: pd.DataFrame) -> pd.Series | pd.DataFrame

Predictions for in-sample, already seen data.

dummy

DummyClassifier

Bases: Model, Tunable

A model that predicts a predefined class with predefined probabilities.

Parameters:

Name Type Description Default
predicted_value (float, int)

The class to predict.

required
all_classes list[int]

All possible classes.

required
predicted_probabilities list[float]

The probabilities returned.

required

Examples:

>>> from fold.loop import train_backtest
>>> from fold.splitters import SlidingWindowSplitter
>>> from fold.models import DummyClassifier
>>> from fold.utils.tests import generate_sine_wave_data
>>> X, y  = generate_sine_wave_data()
>>> splitter = SlidingWindowSplitter(train_window=0.5, step=0.2)
>>> pipeline = DummyClassifier(1, [0, 1], [0.5, 0.5])
>>> preds, trained_pipeline, _, _ = train_backtest(pipeline, X, y, splitter)
>>> preds.head()
                     predictions_DummyClassifier  ...  probabilities_DummyClassifier_1
2021-12-31 15:40:00                            1  ...                              0.5
2021-12-31 15:41:00                            1  ...                              0.5
2021-12-31 15:42:00                            1  ...                              0.5
2021-12-31 15:43:00                            1  ...                              0.5
2021-12-31 15:44:00                            1  ...                              0.5
<BLANKLINE>
[5 rows x 3 columns]

DummyRegressor

Bases: Model, Tunable

A model that predicts a predefined value.

Parameters:

Name Type Description Default
predicted_value float

The value to predict.

required

Examples:

>>> from fold.loop import train_backtest
>>> from fold.splitters import SlidingWindowSplitter
>>> from fold.models import DummyRegressor
>>> from fold.utils.tests import generate_sine_wave_data
>>> X, y  = generate_sine_wave_data()
>>> splitter = SlidingWindowSplitter(train_window=0.5, step=0.2)
>>> pipeline = DummyRegressor(0.1)
>>> preds, trained_pipeline, _, _ = train_backtest(pipeline, X, y, splitter)
>>> preds.head()
                     predictions_DummyRegressor-0.1
2021-12-31 15:40:00                             0.1
2021-12-31 15:41:00                             0.1
2021-12-31 15:42:00                             0.1
2021-12-31 15:43:00                             0.1
2021-12-31 15:44:00                             0.1

random

RandomBinaryClassifier

Bases: Model

A random model that mimics the probability distribution of the target seen during fitting.

RandomClassifier

Bases: Model

A model that predicts random classes and probabilities.

Parameters:

Name Type Description Default
all_classes list[int]

All possible classes.

required
probability_mean float

The mean of the normal distribution used to generate the probabilities.

None

Examples:

>>> import numpy as np
>>> from fold.loop import train_backtest
>>> from fold.splitters import SlidingWindowSplitter
>>> from fold.models import RandomClassifier
>>> from fold.utils.tests import generate_sine_wave_data
>>> X, y  = generate_sine_wave_data()
>>> splitter = SlidingWindowSplitter(train_window=0.5, step=0.2)
>>> np.random.seed(42)
>>> pipeline = RandomClassifier([0,1], [0.5, 0.5])
>>> preds, trained_pipeline, _, _ = train_backtest(pipeline, X, y, splitter)

sklearn

WrapSKLearnClassifier

Bases: Model, Tunable

Wraps an SKLearn Classifier model. There's no need to use it directly, fold automatically wraps all sklearn classifiers into this class.

WrapSKLearnRegressor

Bases: Model, Tunable

Wraps an SKLearn regressor model. There's no need to use it directly, fold automatically wraps all sklearn regressors into this class.

wrappers

gbd