pyoe.models package¶
Submodules¶
pyoe.models.models module¶
- class pyoe.models.models.ArmnetModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu', 'cuda'] = 'cuda')¶
Bases:
ModelTemplate
A simple ARMNet model for classification and regression tasks.
- calculate_loss(X: Tensor, y: Tensor) float ¶
This function is used to calculate the loss of the model.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
- Returns:
the calculated loss.
- Return type:
out (float)
- process_model(lr: float, **kwargs)¶
This function is used to process the model before training.
- Parameters:
lr (float) – the learning rate for the optimizer.
**kwargs – any arguments that you want to pass.
- train_icarl(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, buffer_size: int, need_test: bool = False)¶
iCaRL training process only supports neural network models.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- train_naive(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, need_test: bool = False)¶
In this function, we will train the model using the input data.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- class pyoe.models.models.ChronosModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu', 'cuda'] = 'cpu', prediction_length: int = 1, model_path: Literal['tiny', 'mini', 'small', 'base', 'large'] = 'tiny')¶
Bases:
ModelTemplate
A simple Chronos model for time series forecasting tasks.
- predict_forecast(X: DataFrame, y: DataFrame) TimeSeriesDataFrame ¶
Predict the target value of the input data.
- Parameters:
X (pd.DataFrame) – the input data.
y (pd.DataFrame) – the target value.
- Returns:
the predicted target value of the input data.
- Return type:
out (TimeSeriesDataFrame)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- train_forecast(X: DataFrame, y: DataFrame)¶
Train the model with the input data.
- Parameters:
X (pd.DataFrame) – the input data.
y (pd.DataFrame) – the target value.
- class pyoe.models.models.CluStreamModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple CluStream model for clustering tasks.
- predict_cluster(X: Tensor) Tensor ¶
Predict the cluster of the input data.
- Parameters:
X (torch.Tensor) – features of the input data.
- Returns:
the predicted cluster of the input data.
- Return type:
out (torch.Tensor)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- train_cluster(X: Tensor)¶
Train the model with the input data.
- Parameters:
X (torch.Tensor) – features of the input data.
- class pyoe.models.models.DbStreamModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple DBStream model for clustering tasks.
- predict_cluster(X: Tensor) Tensor ¶
Predict the cluster of the input data.
- Parameters:
X (torch.Tensor) – features of the input data.
- Returns:
the predicted cluster of the input data.
- Return type:
out (torch.Tensor)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- train_cluster(X: Tensor)¶
Train the model with the input data.
- Parameters:
X (torch.Tensor) – features of the input data.
- class pyoe.models.models.DenStreamModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple DenStream model for clustering tasks.
- predict_cluster(X: Tensor) Tensor ¶
Predict the cluster of the input data.
- Parameters:
X (torch.Tensor) – features of the input data.
- Returns:
the predicted cluster of the input data.
- Return type:
out (torch.Tensor)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- train_cluster(X: Tensor)¶
Train the model with the input data.
- Parameters:
X (torch.Tensor) – features of the input data.
- class pyoe.models.models.GdbtModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple GBDT model for classification and regression tasks.
- calculate_loss(X: Tensor, y: Tensor) float ¶
This function is used to calculate the loss of the model.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
- Returns:
the calculated loss.
- Return type:
out (float)
- process_model(**kwargs)¶
This function is used to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- train_icarl(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, buffer_size: int, need_test: bool = False)¶
iCaRL training process only supports neural network models.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- train_naive(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, need_test: bool = False)¶
In this function, we will train the model using the input data.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- class pyoe.models.models.HSTreeDetectorModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple HSTreeDetector model for outlier detection tasks.
- get_outlier(X: Tensor) Tensor ¶
Get the outlier points using PYOD models.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
a 0-1 vector representing the outlier points.
- Return type:
out (torch.Tensor)
- get_outlier_with_stream_model(X: Tensor) Tensor ¶
Get the outlier score of the input data using the HSTree model.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
the outlier score of the input data.
- Return type:
out (torch.Tensor)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- class pyoe.models.models.LodaDetectorModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple LodaDetector model for outlier detection tasks.
- get_outlier(X: Tensor) Tensor ¶
Get the outlier points using PYOD models.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
a 0-1 vector representing the outlier points.
- Return type:
out (torch.Tensor)
- get_outlier_with_stream_model(X: Tensor) Tensor ¶
Get the outlier score of the input data using the LODA model.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
the outlier score of the input data.
- Return type:
out (torch.Tensor)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- class pyoe.models.models.MlpModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu', 'cuda'] = 'cuda')¶
Bases:
ModelTemplate
A simple MLP model for classification and regression tasks.
- calculate_loss(X: Tensor, y: Tensor) float ¶
This function is used to calculate the loss of the model.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
- Returns:
the calculated loss.
- Return type:
out (float)
- process_model(lr: float, **kwargs)¶
This function is used to process the model before training.
- Parameters:
lr (float) – the learning rate of the optimizer.
**kwargs – other arguments that you want to pass.
- train_icarl(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, buffer_size: int, need_test: bool = False)¶
This function iCaRL implements the training process for MLP model.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
buffer_size (int) – the size of the exemplar buffer.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- train_naive(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, need_test: bool = False)¶
In this function, we will train the model using the input data.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- class pyoe.models.models.ModelTemplate(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu', 'cuda'] = 'cuda')¶
Bases:
object
A template class for all models. It contains the common attributes and methods for all models. ATTENTION: If you need to use your own model, you should inherit this class and assign self.net in the __init__ method. The self.net should be a PyTorch model.
- get_device() Literal['cpu', 'cuda'] ¶
This function is used to get the device that you use for training.
- Returns:
the device that you use for training.
- Return type:
out (Literal[“cpu”, “cuda”])
- get_ensemble_number() int ¶
This function is used to get the ensemble number.
- Returns:
the ensemble number.
- Return type:
out (int)
- get_model_type() str ¶
This function is used to get the model type.
- Returns:
the model type.
- Return type:
out (str)
- get_net()¶
This function is used to get the model object.
- Returns:
the model object.
- Return type:
out (Any)
- get_net_ensemble()¶
This function is used to get the ensemble model object.
- Returns:
the ensemble model object.
- Return type:
out (Any)
- abstract process_model(**kwargs)¶
This function is used to process the model before training. You should assign some values for later use in training such as optimizer, criterion, etc. Attention: this function is called in the trainer class.
- Parameters:
**kwargs – any arguments that you want to pass.
- class pyoe.models.models.RShashDetectorModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple RShashDetector model for outlier detection tasks.
- get_outlier(X: Tensor) Tensor ¶
Get the outlier points using PYOD models.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
a 0-1 vector representing the outlier points.
- Return type:
out (torch.Tensor)
- get_outlier_with_stream_model(X: Tensor) Tensor ¶
Get the outlier score of the input data using the RShash model.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
the outlier score of the input data.
- Return type:
out (torch.Tensor)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- class pyoe.models.models.RrcfDetectorModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple RrcfDetector model for outlier detection tasks.
- get_outlier(X: Tensor) Tensor ¶
Get the outlier points using PYOD models.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
a 0-1 vector representing the outlier points.
- Return type:
out (torch.Tensor)
- get_outlier_with_stream_model(X: Tensor) Tensor ¶
Get the outlier score of the input data using the RRCF model.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
the outlier score of the input data.
- Return type:
out (torch.Tensor)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- class pyoe.models.models.StreamKMeansModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple StreamKMeans model for clustering tasks.
- predict_cluster(X: Tensor) Tensor ¶
Predict the cluster of the input data.
- Parameters:
X (torch.Tensor) – features of the input data.
- Returns:
the predicted cluster of the input data.
- Return type:
out (torch.Tensor)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- train_cluster(X: Tensor)¶
Train the model with the input data.
- Parameters:
X (torch.Tensor) – features of the input data.
- class pyoe.models.models.TabnetModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple TabNet model for classification and regression tasks.
- calculate_loss(X: Tensor, y: Tensor) float ¶
This function is used to calculate the loss of the model.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
- Returns:
the calculated loss.
- Return type:
out (float)
- process_model(**kwargs)¶
This function is used to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- train_icarl(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, buffer_size: int, need_test: bool = False)¶
iCaRL training process only supports neural network models.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- train_naive(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, need_test: bool = False)¶
In this function, we will train the model using the input data.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- class pyoe.models.models.TreeModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple Tree model for classification and regression tasks.
- calculate_loss(X: Tensor, y: Tensor) float ¶
This function is used to calculate the loss of the model.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
- Returns:
the calculated loss.
- Return type:
out (float)
- process_model(**kwargs)¶
This function is used to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
- train_icarl(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, buffer_size: int, need_test: bool = False)¶
iCaRL training process only supports neural network models.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
buffer_size (int) – the size of the exemplar buffer.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- train_naive(X: Tensor, y: Tensor, y_outlier: Tensor, batch_size: int, epochs: int, need_test: bool = False)¶
In this function, we will train the model using the input data.
- Parameters:
X (torch.Tensor) – the input data.
y (torch.Tensor) – the target value.
y_outlier (torch.Tensor) – the outlier data.
batch_size (int) – the batch size for training.
epochs (int) – the number of epochs for training.
need_test (bool) – if this parameter is True, the accurate loss will be calculated during training.
- class pyoe.models.models.XStreamDetectorModel(dataloader: Dataloader, ensemble: int = 1, device: Literal['cpu'] = 'cpu')¶
Bases:
ModelTemplate
A simple XStreamDetector model for outlier detection tasks.
- get_outlier(X: Tensor) Tensor ¶
Get the outlier points using PYOD models.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
a 0-1 vector representing the outlier points.
- Return type:
out (torch.Tensor)
- get_outlier_with_stream_model(X: Tensor) Tensor ¶
Get the outlier score of the input data using the XStream model.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
the outlier score of the input data.
- Return type:
out (torch.Tensor)
- process_model(**kwargs)¶
This function is used to process the model before training. In this model, we don’t need to process the model before training.
- Parameters:
**kwargs – any arguments that you want to pass.
pyoe.models.networks module¶
- class pyoe.models.networks.ChronosPredictorNet(prediction_length: int, model_path: Literal['tiny', 'mini', 'small', 'base', 'large'] = 'tiny', device: Literal['cpu', 'cuda'] = 'cpu')¶
Bases:
Module
Chronos model for time series prediction. See https://github.com/amazon-science/chronos-forecasting.
- fit(X: DataFrame, y: DataFrame) None ¶
Learn from the time series data.
- Parameters:
X (pd.DataFrame) – the input data.
y (pd.DataFrame) – the target data.
- forward(X: DataFrame, y: DataFrame) TimeSeriesDataFrame ¶
Predict the future time series data.
- Parameters:
X (pd.DataFrame) – the input data.
y (pd.DataFrame) – the target data.
- Returns:
the predicted time series data.
- Return type:
out (TimeSeriesDataFrame)
- class pyoe.models.networks.CluStreamNet¶
Bases:
ClusterNet
CluStream network for clustering
- class pyoe.models.networks.ClusterNet(stream)¶
Bases:
Module
Cluster network template for clustering with CluStream
- fit(X: Tensor) None ¶
Learn from the data one by one.
- Parameters:
X (torch.Tensor) – the input data.
- forward(X: Tensor) Tensor ¶
Predict cluster assignments for the input data.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
the predicted cluster assignments.
- Return type:
out (torch.Tensor)
- class pyoe.models.networks.DbStreamNet¶
Bases:
ClusterNet
DBStream network for clustering
- class pyoe.models.networks.DenStreamNet¶
Bases:
ClusterNet
DenStream network for clustering
- class pyoe.models.networks.HSTreeDetectorNet¶
Bases:
OutlierDetectorNet
HSTreeDetector model for outlier detection
- class pyoe.models.networks.LodaDetectorNet¶
Bases:
OutlierDetectorNet
LodaDetector model for outlier detection
- class pyoe.models.networks.OutlierDetectorNet(model)¶
Bases:
Module
- forward(X: Tensor) Tensor ¶
Predict cluster assignments for the input data.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
the predicted cluster assignments.
- Return type:
out (torch.Tensor)
- get_model_score(X: Tensor) Tensor ¶
Using a stream model to get the anomaly score, and with this function you could compare the result with the ground truth to evaluate the model.
- Parameters:
X (torch.Tensor) – the input data.
- Returns:
the anomaly score of the input data.
- Return type:
out (torch.Tensor)
- static outlier_detector_marker(data)¶
This function is used to detect outliers in the input data.
- Parameters:
data (np.ndarray) – the input data.
- Returns:
the detected outliers.
- Return type:
out (np.ndarray)
- class pyoe.models.networks.RShashDetectorNet¶
Bases:
OutlierDetectorNet
RShashDetector model for outlier detection
- class pyoe.models.networks.RrcfDetectorNet¶
Bases:
OutlierDetectorNet
RrcfDetector model for outlier detection
- class pyoe.models.networks.StreamKMeansNet¶
Bases:
ClusterNet
StreamKMeans network for clustering
- class pyoe.models.networks.XStreamDetectorNet¶
Bases:
OutlierDetectorNet
xStreamDetector model for outlier detection