MatchingKernelQuantifier#
- class mlquantify.matching.MatchingKernelQuantifier(kernel='rbf', gamma=None, degree=3, coef0=0.0, solver='slsqp')[source]#
Abstract base class for kernel mean matching quantifiers.
Estimates class prevalences by minimising the distance between the kernel mean embedding of the test data and the mixture of class-conditional kernel mean embeddings computed on training data.
- Parameters:
- kernelstr, default=’rbf’
Kernel function to use. One of
'rbf','linear','poly','sigmoid','cosine'.- gammafloat or None, default=None
Kernel coefficient for
'rbf','poly', and'sigmoid'. IfNone, uses1 / n_features.- degreeint, default=3
Polynomial degree for the
'poly'kernel.- coef0float, default=0.0
Independent term for
'poly'and'sigmoid'kernels.- solverstr, default=’slsqp’
Optimization solver.
- Attributes:
- classes_ndarray of shape (n_classes,)
Class labels seen during
fit.
Examples
>>> from mlquantify.matching._kernel import MatchingKernelQuantifier >>> from sklearn.datasets import make_classification >>> import numpy as np >>> class MyKernelQ(MatchingKernelQuantifier): ... def fit(self, X, y): ... self.classes_ = np.unique(y) ... return self._fit(X, y) ... def predict(self, X): ... return self._predict(X) >>> X, y = make_classification(n_samples=200, random_state=42) >>> MyKernelQ().fit(X, y).predict(X) {0: 0.49, 1: 0.51}
- get_distance(dist_train, dist_test, distance='hellinger')[source]#
Compute a distance between two normalized representations.
- get_metadata_routing()[source]#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- get_params(deep=True)[source]#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- set_params(**params)[source]#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.