olpy.classifiers.ALMA
- class olpy.classifiers.ALMA(alpha=1.0, p=2, C=1, num_iterations=1, random_state=None, class_weight=None, positive_label=1)[source]
Bases:
olpy.classifiers.__base.OnlineLearningModelA New Approximate Maximal Margin Classification Algorithm.
Gentile, C. A New Approximate Maximal Margin Classification Algorithm Journal of Machine Learning Research, 101, 2, 213-242
- alpha
The sensitivity of the model. alpha takes values between 0 (non-inclusive). Defaults to 1.
- Type
float, optional
- random_state
The random seed to use with the pseudo-random generator. Defaults to None.
- Type
int, optional
- positive_label
The number in the output field that represents the positive label. The value passed should be different than -1. Defaults to 1.
- Type
int, optional
- class_weight
Represents the relative weight of the labels in the data. Useful for imbalanced classification tasks.
- Type
dict, optional
- Raises
AssertionError – if positive_label is equal to -1.
Methods
Compute the values of the decision boundaries.
Fits the model to the (X,Y) pair passed to the function.
Get parameters for this estimator.
Trains the model on a single data point.
Predict the label given the test dataset X.
Compute the probability that a model is from a class.
Compute the score performed on the dataset.
Set the parameters of this estimator.
- decision_function(X)
Compute the values of the decision boundaries.
Given an unlabelled data, this method computes the probabilities of being assigned the positive label.
- fit(X: numpy.ndarray, Y: numpy.ndarray, verbose=False, **kwargs)
Fits the model to the (X,Y) pair passed to the function.
- Parameters
X (
numpy.ndarray) – Input data with n rows and m columnsY (
numpy.ndarray) – Output variable with binary labels.verbose (
bool, optional) – Specifies whether the performances should be reported or not. Defaults to False.kwargs (**) – Arbitrary keyword arguments.
- Returns
the trained model.
- Return type
self
- get_params(deep=True)[source]
Get parameters for this estimator.
This function is for use with hyper-parameter tuning utilities such as GridSearchCV.
- Parameters
deep (
bool, optional) – If True, will return the parametersare (for this estimator and contained sub-objects that) –
True. (estimators. Defaults to) –
- partial_fit(X, Y, classes=None)
Trains the model on a single data point.
- Parameters
X (
numpy.ndarray) – Input data with n rows and m columnsY (
numpy.ndarray) – Output variable with binary labels.classes (
listor tuple, optional) – Represents the available labels in the dataset. Needs to be passed only once.
- Returns
the trained model.
- Return type
self
- predict(X)
Predict the label given the test dataset X.
Given an unlabelled data, this function predicts the labels to be assigned to it based on the weights learned so far.
- Parameters
X (
numpy.ndarrayor list) – unlabelled data.- Returns
np.ndarray with dimension (n,) representing the output labels.
- Raises
NotFittedError – when the method is called without prior
fitting. –
- predict_proba(X)
Compute the probability that a model is from a class.
Given an unlabelled data, this method returns the probability for each data point to belong to either class.
- Parameters
X (
numpy.ndarray) – Input data with n rows and m columns- Returns
- the probabilities of the
data points belonging to each class.
- Return type
listof size (n, 2)
- score(X, y)
Compute the score performed on the dataset.
Given a labelled data, this method evaluate the performance of the models by predicting and computing the accuracy score.
Note
Different models can override the function to return a different metric.
- Parameters
X (
numpy.ndarray) – Input data with n rows and m columnsY (
, `numpy.ndarray) – Output variable with binary labels.
- Returns
The accuracy score of the model given the labelled data.
- Return type
- set_params(**parameters)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
- Parameters
parameters (**) – Estimator parameters.
- Returns
estimator instance.
- Return type
self