CrispPredictionMixin#

class mlquantify.base_aggregative.CrispPredictionMixin[source]#

Crisp predictions mixin for aggregative quantifiers.

This mixin provides the following change tags: - estimator_function: “predict” - estimator_type: “crisp”

Notes

  • This mixin should be used alongside the AggregativeMixin, in

the left of it in the inheritance order.

Examples

>>> from mlquantify.base import BaseQuantifier
>>> from mlquantify.base_aggregative import AggregativeMixin, CrispPredictionMixin
>>> from sklearn.linear_model import LogisticRegression
>>> import numpy as np
>>> class MyCrispAggregativeQuantifier(CrispPredictionMixin, AggregativeMixin, BaseQuantifier):
...     def __init__(self, estimator=None):
...         self.estimator = estimator if estimator is not None else LogisticRegression()
...     def fit(self, X, y):
...         self.estimator.fit(X, y)
...         self.classes_ = np.unique(y)
...         return self
...     def predict(self, X):
...         preds = self.estimator.predict(X)
...         _, counts = np.unique(preds, return_counts=True)
...         prevalence = counts / counts.sum()
...         return prevalence
>>> quantifier = MyCrispAggregativeQuantifier()
>>> X = np.random.rand(100, 10)
>>> y = np.random.randint(0, 2, size=100)
>>> quantifier.fit(X, y).predict(X)
[0.5 0.5]