CrispLearnerQMixin#
- class mlquantify.base_aggregative.CrispLearnerQMixin[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
AggregationMixin, in
the left of it in the inheritance order.
Examples
>>> from mlquantify.base import BaseQuantifier, AggregationMixin, CrispLearnerQMixin >>> from sklearn.linear_model import LogisticRegression >>> import numpy as np >>> class MyCrispAggregativeQuantifier(CrispLearnerQMixin, AggregationMixin, BaseQuantifier): ... def __init__(self, learner=None): ... self.learner = learner if learner is not None else LogisticRegression() ... def fit(self, X, y): ... self.learner.fit(X, y) ... self.classes_ = np.unique(y) ... return self ... def predict(self, X): ... preds = self.learner.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]