leaspy.models.base

Classes

InitializationMethod

str(object='') -> str

BaseModel

Base model class from which all Leaspy models should inherit.

Module Contents

class InitializationMethod

Bases: str, enum.Enum

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

DEFAULT = 'default'
RANDOM = 'random'
class BaseModel(name, **kwargs)

Bases: abc.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

Number of features.

Parameters:

name (str)

is_initialized: bool = False
name
property features: list[leaspy.utils.typing.FeatureType] | None
Return type:

Optional[list[leaspy.utils.typing.FeatureType]]

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.

Return type:

Optional[int]

initialize(dataset=None, method=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, optional

The dataset we want to initialize from.

methodInitializationMethod, optional

A custom method to initialize the model

Parameters:
Return type:

None

abstractmethod save(path, **kwargs)

Save Leaspy object as json model parameter file.

Parameters:
pathstr

Path to store the model’s parameters.

**kwargs

Additional parameters for writing.

Parameters:

path (str)

Return type:

None