SoftLearnerQMixin#
- class mlquantify.base_aggregative.SoftLearnerQMixin[source]#
Soft predictions mixin for aggregative quantifiers.
This mixin provides the following change tags: -
estimator_function: “predict_proba” -estimator_type: “soft”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, SoftLearnerQMixin >>> from sklearn.linear_model import LogisticRegression >>> import numpy as np >>> class MySoftAggregativeQuantifier(SoftLearnerQMixin, 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): ... proba = self.learner.predict_proba(X) ... return proba.mean(axis=0) >>> quantifier = MySoftAggregativeQuantifier() >>> X = np.random.rand(100, 10) >>> y = np.random.randint(0, 2, size=100) >>> quantifier.fit(X, y).predict(X) [0.5 0.5]