QuaPy/quapy/method/non_aggregative.py

36 lines
1.3 KiB
Python
Raw Normal View History

2021-01-15 18:32:32 +01:00
from quapy.data import LabelledCollection
2020-12-03 18:12:28 +01:00
from .base import BaseQuantifier
class MaximumLikelihoodPrevalenceEstimation(BaseQuantifier):
2021-12-15 15:27:43 +01:00
"""
The `Maximum Likelihood Prevalence Estimation` (MLPE) method is a lazy method that assumes there is no prior
probability shift between training and test instances (put it other way, that the i.i.d. assumpion holds).
The estimation of class prevalence values for any test sample is always (i.e., irrespective of the test sample
itself) the class prevalence seen during training. This method is considered to be a lower-bound quantifier that
any quantification method should beat.
"""
def __init__(self):
self._classes_ = None
2020-12-03 18:12:28 +01:00
2021-12-15 15:27:43 +01:00
def fit(self, data: LabelledCollection):
"""
Computes the training prevalence and stores it.
:param data: the training sample
:return: self
"""
2020-12-03 18:12:28 +01:00
self.estimated_prevalence = data.prevalence()
return self
2020-12-03 18:12:28 +01:00
2021-12-15 15:27:43 +01:00
def quantify(self, instances):
"""
Ignores the input instances and returns, as the class prevalence estimantes, the training prevalence.
:param instances: array-like (ignored)
:return: the class prevalence seen during training
"""
2020-12-03 18:12:28 +01:00
return self.estimated_prevalence