1
0
Fork 0
QuaPy/quapy/method/non_aggregative.py

63 lines
1.9 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
"""
self._classes_ = data.classes_
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
@property
def classes_(self):
2021-12-15 15:27:43 +01:00
"""
Number of classes
:return: integer
"""
return self._classes_
2021-12-15 15:27:43 +01:00
def get_params(self, deep=True):
"""
Does nothing, since this learner has no parameters.
:param deep: for compatibility with sklearn
:return: `None`
"""
return None
2020-12-03 18:12:28 +01:00
def set_params(self, **parameters):
2021-12-15 15:27:43 +01:00
"""
Does nothing, since this learner has no parameters.
:param parameters: dictionary of param-value pairs (ignored)
"""
2020-12-03 18:12:28 +01:00
pass