leaspy.models.BaseModel

class BaseModel(name: str, **kwargs)

Bases: ABC

Base model class from which all Leaspy models should inherit.

It defines the interface that a model should implement to be compatible with Leaspy.

Parameters:
namestr

The name of the model.

**kwargs

Hyperparameters of the model

Attributes:
namestr

The name of the model.

is_initializedbool

True``if the model is initialized, ``False otherwise.

featureslist of str

List of model features (None if not initialization).

dimensionint

The dimension of the model.

Methods

initialize(dataset[, method])

Initialize the model given a Dataset and an initialization method.

save(path, **kwargs)

Save Leaspy object as json model parameter file.

validate_compatibility_of_dataset(dataset)

Raise if the given Dataset is not compatible with the current model.

property dimension: int | None

The dimension of the model. If the private attribute is defined, then it takes precedence over the feature length. The associated setters are responsible for their coherence.

initialize(dataset: Dataset, method: str = 'default') None

Initialize the model given a Dataset and an initialization method.

After calling this method is_initialized should be True and model should be ready for use.

Parameters:
datasetDataset

The dataset we want to initialize from.

methodstr

A custom method to initialize the model

abstract save(path: str, **kwargs) None

Save Leaspy object as json model parameter file.

Parameters:
pathstr

Path to store the model’s parameters.

**kwargs

Additional parameters for writing.

validate_compatibility_of_dataset(dataset: Dataset) None

Raise if the given Dataset is not compatible with the current model.

Parameters:
datasetDataset

The Dataset we want to model.

Raises:
LeaspyModelInputError
  • If the Dataset has a number of dimensions smaller than 2.

  • If the Dataset does not have the same dimensionality as the model.

  • If the Dataset’s headers do not match the model’s.