olpy.classifiers

The repository of all the binary classifiers implemented with the package.

This module exposes a series of online machine learning models that can be used for binary classification. The models learn by taking one data point at a time and can achieve very good accuracy results.

One of the features of the models is to allow for usage of class weights during the training process. They also permit to train using a single data point with the partial_fit method.

Examples

Training a model

>>> from olpy.classifiers import AROW
>>> from olpy.datasets import load_a1a
>>> from sklearn.metrics import accuracy_score
>>> a1a = load_a1a()
>>> model = AROW(random_state = 32)
>>> _ = model.fit(a1a.train_data, a1a.train_target)
>>> prediction = model.predict(a1a.test_data)
>>> accuracy_score(a1a.test_target, prediction)
0.8379312572683809

Using the weights to change the performance

>>> model = AROW(random_state=32, class_weight=np.list([0.4, 0.6]))
>>> _ = model.fit(a1a.train_data, a1a.train_target)
>>> prediction = model.predict(a1a.test_data)
>>> accuracy_score(a1a.test_target, prediction)
0.838254296417262

Doing a partial learn (meant for active learning processes)

>>> import random
>>> import numpy as np
>>> random.seed(32)
>>> model = AROW(random_state = 32)
>>> for i in random.sample(range(a1a.train_data.shape[0]), k=10):
...     model = model.partial_fit(np.expand_dims(a1a.train_data[i], axis=0), [a1a.train_target[i]])
>>> prediction = model.predict(a1a.test_data)
>>> accuracy_score(a1a.test_target, prediction)
0.13551492440883836

Classes

ALMA

A New Approximate Maximal Margin Classification Algorithm.

AROW

The Adaptive Regularization of Weight vectors model.

CW

The Confidence-Weighted model.

ECCW

The Exact convex confidence-weighted learning model.

IELLIP

The Improved Ellipsoid model.

NAROW

New adaptive algorithms for online classification

NHerd

Gaussian Herding model.

OGD

Online Gradient Descent model.

PA

Passive-Aggressive Model.

PA_I

Passive Aggressive-I Model.

PA_II

Passive Aggressive-II Model.

Perceptron

The Perceptron model.

ROMMA

The Relaxed Online Maximum Margin Algorithm.

SCW

Soft Confidence Weighted model.

SCW2

Soft Confidence Weighted variant 2 model.

SecondOrderPerceptron

Second Order Perceptron model.

aROMMA

The (Aggressive) Relaxed Online Maximum Margin Algorithm.