Skip to main content
Version: 0.5.x

BaseClassifier

Abstract base class for classification algorithms.

Module: aisp.base
Import: from aisp.base import BaseClassifier


Overview

This class defines the core interface for classification models. It enforces the implementation of the fit and predict methods in all derived classes, and provides a default implementation of the score method.

Use cases:

  • Abstract base class for extending classification algorithm classes.

Attributes

NameTypeDefaultDescription
classesOptional[npt.NDArray]NoneClass labels identified during training.

Abstract Methods

fit

@abstractmethod
def fit(
self,
X: Union[npt.NDArray, list],
y: Union[npt.NDArray, list],
verbose: bool = True
) -> BaseClassifier:
...

Train the model using the input data X and corresponding labels y.
This abstract method is implemented by the class that inherits it.

Parameters

NameTypeDefaultDescription
XUnion[npt.NDArray, list]-Training input samples. Each row corresponds to a samples and column to feature.
yUnion[npt.NDArray, list]-Target vector of shape (n_samples,). Must contain the same number of samples as X.
verboseboolTrueIf True, prints training progress information.

Returns

TypeDescription
SelfReturns the instance of the class that implements this method.

predict

@abstractmethod
def predict(self, X: Union[npt.NDArray, list]) -> npt.NDArray:
...

Generate predictions based on the input data X.
This abstract method is implemented by the class that inherits it.

Parameters

NameTypeDefaultDescription
XUnion[npt.NDArray, list]-Input samples. Must have the same number of features used during training.

Returns

TypeDescription
npt.NDArrayPredicted values for each input sample.

Public Methods

score

def score(
self,
X: Union[npt.NDArray, list],
y: Union[npt.NDArray, list]
) -> float:
...

Score function calculates forecast accuracy.

This function performs the prediction of X and checks how many elements are equal between vector y and y_predicted. This function was added for compatibility with some scikit-learn functions.

Parameters

NameTypeDefaultDescription
XUnion[npt.NDArray, list]-Feature set with shape (n_samples, n_features).
yUnion[npt.NDArray, list]-True values with shape (n_samples,).

Returns

TypeDescription
floatThe accuracy of the model.