ZeroRuleClassifier classifier implementation.
Classes
Zero Rule classifier that predicts the most frequent class, ignoring all input features.
ZeroRuleClassifier is the simplest classification method which relies only on the target distribution and ignores all predictors. It simply predicts the majority class (mode) for classification tasks. This classifier is useful as a baseline -- any classifier that cannot beat ZeroRuleClassifier should be discarded.
Constructor
__init__( self, )
Overview
The algorithm operates as follows:
- During training, compute the frequency of each class label
- Store the majority class (the class with the highest count)
- At prediction time, return the majority class for every instance
Theory
The prediction for all instances is the mode of the training labels:
\hat{y} = \arg\max_{c \in C} \sum_{i=1}^{n} \mathbb{1}[y_i = c]
The expected error rate of ZeroRuleClassifier equals the proportion of non-majority instances:
\text{Error} = 1 - \frac{\max_{c} n_c}{n}
where n_c is the count of class c and n is the total number of training instances.
Attributes
majority_class_
any
The most frequent class in training data.
class_counts_
dict
Count of each class in training data.
classes_
np.ndarray
Unique classes in training data.
Notes
Complexity:
- Training: O(n) where n = number of samples
- Prediction: O(1) per sample
- As the absolute baseline for any classification task
- To establish the minimum acceptable accuracy threshold
- When comparing classifier performance: any useful model must beat it
- For sanity-checking evaluation pipelines
References
Witten2011
Witten, I.H., Frank, E. and Hall, M.A. (2011).
Data Mining: Practical Machine Learning Tools and Techniques.
Morgan Kaufmann, 3rd Edition.
DOI: 10.1016/C2009-0-19715-5
See Also
Basic usage as a baseline classifier:
python
>>> from tuiml.algorithms.rules import ZeroRuleClassifier
>>> import numpy as np
>>>
>>> # Create sample data
>>> X_train = np.array([[1, 2], [2, 3], [3, 1], [4, 3], [5, 2]])
>>> y_train = np.array([0, 0, 1, 1, 1])
>>>
>>> # Fit the model
>>> clf = ZeroRuleClassifier()
>>> clf.fit(X_train, y_train)
ZeroRuleClassifier(...)
>>> # Predicts majority class (1) for all instances
>>> predictions = clf.predict(X_train)
>>> print(predictions)
[1 1 1 1 1]
Methods
fit
(self, X: np.ndarray, y: np.ndarray) -> 'ZeroRuleClassifier'
fit
(self, X: np.ndarray, y: np.ndarray) -> 'ZeroRuleClassifier'
Fit the ZeroRuleClassifier classifier.
Parameters
X
np.ndarray of shape (n_samples, n_features)
Training features. Ignored by ZeroRuleClassifier.
y
np.ndarray of shape (n_samples,)
Target labels.
Returns
self
ZeroRuleClassifier
Returns the fitted instance.