Skip to content

rolling_classifier

RollingClassifier(module, loss_fn='binary_cross_entropy_with_logits', optimizer_fn='sgd', lr=0.001, output_is_logit=True, is_class_incremental=False, is_feature_incremental=False, device='cpu', seed=42, window_size=10, append_predict=False, **kwargs)

Bases: Classifier, RollingDeepEstimator

Wrapper that feeds a sliding window of the most recent examples to the wrapped PyTorch classification model. The class also automatically handles increases in the number of classes by adding output neurons in case the number of observed classes exceeds the current number of output neurons.

PARAMETER DESCRIPTION
module

Torch Module that builds the autoencoder to be wrapped. The Module should accept parameter n_features so that the returned model's input shape can be determined based on the number of features in the initial training example.

TYPE: Type[Module]

loss_fn

Loss function to be used for training the wrapped model. Can be a loss function provided by torch.nn.functional or one of the following: 'mse', 'l1', 'cross_entropy', 'binary_crossentropy', 'smooth_l1', 'kl_div'.

TYPE: Union[str, Callable] DEFAULT: 'binary_cross_entropy_with_logits'

optimizer_fn

Optimizer to be used for training the wrapped model. Can be an optimizer class provided by torch.optim or one of the following: "adam", "adam_w", "sgd", "rmsprop", "lbfgs".

TYPE: Union[str, Callable] DEFAULT: 'sgd'

lr

Learning rate of the optimizer.

TYPE: float DEFAULT: 0.001

output_is_logit
Whether the module produces logits as output. If true, either
softmax or sigmoid is applied to the outputs when predicting.

TYPE: bool DEFAULT: True

is_class_incremental

Whether the classifier should adapt to the appearance of previously unobserved classes by adding an unit to the output layer of the network. This works only if the last trainable layer is an nn.Linear layer. Note also, that output activation functions can not be adapted, meaning that a binary classifier with a sigmoid output can not be altered to perform multi-class predictions.

TYPE: bool DEFAULT: False

is_feature_incremental

Whether the model should adapt to the appearance of previously features by adding units to the input layer of the network.

TYPE: bool DEFAULT: False

device

Device to run the wrapped model on. Can be "cpu" or "cuda".

TYPE: str DEFAULT: 'cpu'

seed

Random seed to be used for training the wrapped model.

TYPE: int DEFAULT: 42

window_size

Number of recent examples to be fed to the wrapped model at each step.

TYPE: int DEFAULT: 10

append_predict

Whether to append inputs passed for prediction to the rolling window.

TYPE: bool DEFAULT: False

**kwargs

Parameters to be passed to the build_fn function aside from n_features.

DEFAULT: {}

learn_many(x, y)

Performs one step of training with the most recent training examples stored in the sliding window.

PARAMETER DESCRIPTION
x

Input examples.

TYPE: DataFrame

y

Target values.

TYPE: Series

RETURNS DESCRIPTION
Classifier

The classifier itself.

learn_one(x, y, **kwargs)

Performs one step of training with the most recent training examples stored in the sliding window.

PARAMETER DESCRIPTION
x

Input example.

TYPE: dict

y

Target value.

TYPE: ClfTarget

RETURNS DESCRIPTION
Classifier

The classifier itself.

predict_proba_many(x)

Predict the probability of each label given the most recent examples

PARAMETER DESCRIPTION
x

TYPE: DataFrame

RETURNS DESCRIPTION
DataFrame

DataFrame of probabilities for each label.

predict_proba_one(x)

Predict the probability of each label given the most recent examples stored in the sliding window.

PARAMETER DESCRIPTION
x

Input example.

TYPE: dict

RETURNS DESCRIPTION
Dict[ClfTarget, float]

Dictionary of probabilities for each label.