Base class for classification algorithm.
class BaseClassifier(ABC, Base):
Base class for classification algorithms, defining the abstract methods fit and predict, and implementing the get_params method.
Abstract methods
def fit(...)
def fit(self, X: npt.NDArray, y: npt.NDArray, verbose: bool = True)
Fit the model to the training data.
Implementation:
def predict(...)
def predict(self, X) -> Optional[npt.NDArray]:
Performs label prediction for the given data.
Implementation:
Methods
def score(...)
def score(self, X: npt.NDArray, y: 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:
- X:
np.ndarrayFeature set with shape (n_samples, n_features). - y:
np.ndarrayTrue values with shape (n_samples,).
Returns:
- accuracy:
floatThe accuracy of the model.
Function _slice_index_list_by_class(...)
The function __slice_index_list_by_class(...), separates the indices of the lines according to the output class, to go through the sample array, only in the positions that the output is the class that is being trained:
def __slice_index_list_by_class(self, y: npt.NDArray) -> dict:
Returns a dictionary with the classes as key and the indices in X of the samples.