onelearn.OnlineDummyClassifier

class onelearn.OnlineDummyClassifier(n_classes, dirichlet=None)[source]

A dummy online classifier only using past frequencies of the labels. Namely, predictions don’t use the features and simply compute

(count + dirichlet) / (n_samples + dirichlet * n_classes)

for each class, where count is the count for the class, and where dirichlet is a “smoothing” parameter. This is simply a regularized class frequency with a dirichlet prior with dirichlet parameter

Note

This class cannot produce serious predictions, and must only be used as a dummy baseline.

__init__(n_classes, dirichlet=None)[source]

Instantiates a OnlineDummyClassifier instance.

Parameters:
  • n_classes (int) – Number of expected classes in the labels. This is required since we don’t know the number of classes in advance in a online setting.
  • dirichlet (float or None, default = None) – Regularization level of the class frequencies used for predictions in each node. Default is dirichlet=0.5 for n_classes=2 and dirichlet=0.01 otherwise.

Methods

__init__(n_classes[, dirichlet]) Instantiates a OnlineDummyClassifier instance.
partial_fit(X, y[, classes]) Updates the classifier with the given batch of samples.
predict(X) Predicts the labels for the given features vectors
predict_proba(X) Predicts the class probabilities for the given features vectors

Attributes

dirichlet Regularization level of the class frequencies.
n_classes Number of expected classes in the labels.
dirichlet

Regularization level of the class frequencies.

Type:float or None
n_classes

Number of expected classes in the labels.

Type:int
partial_fit(X, y, classes=None)[source]

Updates the classifier with the given batch of samples.

Parameters:
  • X (np.ndarray or scipy.sparse.csr_matrix, shape=(n_samples, n_features)) – Input features matrix.
  • y (np.ndarray) – Input labels vector.
  • classes (None) – Must not be used, only here for backwards compatibility
Returns:

output – Updated instance of OnlineDummyClassifier

Return type:

OnlineDummyClassifier

predict(X)[source]

Predicts the labels for the given features vectors

Parameters:X (np.ndarray or scipy.sparse.csr_matrix, shape=(n_samples, n_features)) – Input features matrix to predict for.
Returns:output – Returns the predicted labels for the input features
Return type:np.ndarray, shape=(n_samples,)
predict_proba(X)[source]

Predicts the class probabilities for the given features vectors

Parameters:X (np.ndarray or scipy.sparse.csr_matrix, shape=(n_samples, n_features)) – Input features matrix to predict for.
Returns:output – Returns the predicted class probabilities for the input features
Return type:np.ndarray, shape=(n_samples, n_classes)