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
| Name | Type | Default | Description |
|---|---|---|---|
classes | Optional[npt.NDArray] | None | Class 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
| Name | Type | Default | Description |
|---|---|---|---|
X | Union[npt.NDArray, list] | - | Training input samples. Each row corresponds to a samples and column to feature. |
y | Union[npt.NDArray, list] | - | Target vector of shape (n_samples,). Must contain the same number of samples as X. |
verbose | bool | True | If True, prints training progress information. |
Returns
| Type | Description |
|---|---|
Self | Returns 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
| Name | Type | Default | Description |
|---|---|---|---|
X | Union[npt.NDArray, list] | - | Input samples. Must have the same number of features used during training. |
Returns
| Type | Description |
|---|---|
npt.NDArray | Predicted 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
| Name | Type | Default | Description |
|---|---|---|---|
X | Union[npt.NDArray, list] | - | Feature set with shape (n_samples, n_features). |
y | Union[npt.NDArray, list] | - | True values with shape (n_samples,). |
Returns
| Type | Description |
|---|---|
float | The accuracy of the model. |