mlquantify 0.1.14__py3-none-any.whl → 0.1.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mlquantify/adjust_counting/_adjustment.py +22 -15
- {mlquantify-0.1.14.dist-info → mlquantify-0.1.16.dist-info}/METADATA +1 -1
- {mlquantify-0.1.14.dist-info → mlquantify-0.1.16.dist-info}/RECORD +5 -5
- {mlquantify-0.1.14.dist-info → mlquantify-0.1.16.dist-info}/WHEEL +0 -0
- {mlquantify-0.1.14.dist-info → mlquantify-0.1.16.dist-info}/top_level.txt +0 -0
|
@@ -2,6 +2,7 @@ import numpy as np
|
|
|
2
2
|
from abc import abstractmethod
|
|
3
3
|
from scipy.optimize import minimize
|
|
4
4
|
import warnings
|
|
5
|
+
from sklearn.metrics import confusion_matrix
|
|
5
6
|
|
|
6
7
|
from mlquantify.adjust_counting._base import BaseAdjustCount
|
|
7
8
|
from mlquantify.adjust_counting._counting import CC, PCC
|
|
@@ -203,13 +204,13 @@ class MatrixAdjustment(BaseAdjustCount):
|
|
|
203
204
|
self.CM = np.zeros((n_class, n_class))
|
|
204
205
|
|
|
205
206
|
if self.solver == 'optim':
|
|
206
|
-
priors = np.array(list(CC().aggregate(train_y_pred).values()))
|
|
207
|
+
priors = np.array(list(CC().aggregate(train_y_pred, train_y_values).values()))
|
|
207
208
|
self.CM = self._compute_confusion_matrix(train_y_pred, train_y_values, priors)
|
|
208
|
-
prevs_estim = self._get_estimations(predictions > priors)
|
|
209
|
+
prevs_estim = self._get_estimations(predictions > priors, train_y_values)
|
|
209
210
|
prevalence = self._solve_optimization(prevs_estim, priors)
|
|
210
211
|
else:
|
|
211
|
-
self.CM = self._compute_confusion_matrix(train_y_pred)
|
|
212
|
-
prevs_estim = self._get_estimations(predictions)
|
|
212
|
+
self.CM = self._compute_confusion_matrix(train_y_pred, train_y_values)
|
|
213
|
+
prevs_estim = self._get_estimations(predictions, train_y_values)
|
|
213
214
|
prevalence = self._solve_linear(prevs_estim)
|
|
214
215
|
|
|
215
216
|
return prevalence
|
|
@@ -260,11 +261,11 @@ class MatrixAdjustment(BaseAdjustCount):
|
|
|
260
261
|
result = minimize(objective, init, constraints=constraints, bounds=bounds)
|
|
261
262
|
return result.x if result.success else priors
|
|
262
263
|
|
|
263
|
-
def _get_estimations(self, predictions):
|
|
264
|
+
def _get_estimations(self, predictions, train_y_values):
|
|
264
265
|
"""Return prevalence estimates using CC (crisp) or PCC (probabilistic)."""
|
|
265
266
|
if uses_soft_predictions(self):
|
|
266
267
|
return np.array(list(PCC().aggregate(predictions).values()))
|
|
267
|
-
return np.array(list(CC().aggregate(predictions).values()))
|
|
268
|
+
return np.array(list(CC().aggregate(predictions, train_y_values).values()))
|
|
268
269
|
|
|
269
270
|
@abstractmethod
|
|
270
271
|
def _compute_confusion_matrix(self, predictions, *args):
|
|
@@ -389,8 +390,11 @@ class GAC(CrispLearnerQMixin, MatrixAdjustment):
|
|
|
389
390
|
def __init__(self, learner=None):
|
|
390
391
|
super().__init__(learner=learner, solver='linear')
|
|
391
392
|
|
|
392
|
-
def _compute_confusion_matrix(self, predictions):
|
|
393
|
-
|
|
393
|
+
def _compute_confusion_matrix(self, predictions, y_values):
|
|
394
|
+
self.CM = confusion_matrix(y_values, predictions, labels=self.classes_).T
|
|
395
|
+
self.CM = self.CM.astype(float)
|
|
396
|
+
prev_estim = self.CM.sum(axis=0)
|
|
397
|
+
|
|
394
398
|
for i, _ in enumerate(self.classes_):
|
|
395
399
|
if prev_estim[i] == 0:
|
|
396
400
|
self.CM[i, i] = 1
|
|
@@ -448,13 +452,16 @@ class GPAC(SoftLearnerQMixin, MatrixAdjustment):
|
|
|
448
452
|
def __init__(self, learner=None):
|
|
449
453
|
super().__init__(learner=learner, solver='linear')
|
|
450
454
|
|
|
451
|
-
def _compute_confusion_matrix(self, posteriors):
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
455
|
+
def _compute_confusion_matrix(self, posteriors, y_values):
|
|
456
|
+
n_classes = len(self.classes_)
|
|
457
|
+
confusion = np.eye(n_classes)
|
|
458
|
+
|
|
459
|
+
for i, class_label in enumerate(self.classes_):
|
|
460
|
+
indices = (y_values == class_label)
|
|
461
|
+
if np.any(indices):
|
|
462
|
+
confusion[i] = posteriors[indices].mean(axis=0)
|
|
463
|
+
|
|
464
|
+
self.CM = confusion.T
|
|
458
465
|
return self.CM
|
|
459
466
|
|
|
460
467
|
|
|
@@ -5,7 +5,7 @@ mlquantify/calibration.py,sha256=chG3GNX2BBDTWIuSVfZUJ_YF_ZVBSoel2d_AN0OChS0,6
|
|
|
5
5
|
mlquantify/confidence.py,sha256=QkEWr6s-Su3Nbinia_TRQbBeTM6ymDPe7Bv204XBKKA,10799
|
|
6
6
|
mlquantify/multiclass.py,sha256=wFbbXKqGsFVSsI9zC0EHGYyyx1JRxFpzMi_q8l80TUM,11770
|
|
7
7
|
mlquantify/adjust_counting/__init__.py,sha256=AWio99zeaUULQq9vKggkFhnq-tqgXxasQt167NdcNVY,307
|
|
8
|
-
mlquantify/adjust_counting/_adjustment.py,sha256=
|
|
8
|
+
mlquantify/adjust_counting/_adjustment.py,sha256=412kFnx3-noaA9u9AatuGIvJbKze-PLPFfBFMBVmQVA,23635
|
|
9
9
|
mlquantify/adjust_counting/_base.py,sha256=MjBsNG7wE0Z_KToXX8WbthhVvz-yc0-d2zIqPo1CB9g,9429
|
|
10
10
|
mlquantify/adjust_counting/_counting.py,sha256=6PKea54xvsga8spNEbsngKNQPyGUXzOkCRyXQR8rTdo,5699
|
|
11
11
|
mlquantify/adjust_counting/_utils.py,sha256=DEPNzvcr0KszCnfUJaRzBilwWzuNVMSdy5eV7aQ_JPE,2907
|
|
@@ -47,7 +47,7 @@ mlquantify/utils/_sampling.py,sha256=QQxE2WKLdiCFUfPF6fKgzyrsOUIWYf74w_w8fbYVc2c
|
|
|
47
47
|
mlquantify/utils/_tags.py,sha256=Rz78TLpxgVxBKS0mKTlC9Qo_kn6HaEwVKNXh8pxFT7M,1095
|
|
48
48
|
mlquantify/utils/_validation.py,sha256=TGGnfv7F5rnQmVeSqGMuS9AP76O974b1TPishKCCWls,16800
|
|
49
49
|
mlquantify/utils/prevalence.py,sha256=FXLCJViQb2yDbyTXeGZt8WsPPnSZINhorQYZTKXOn14,1772
|
|
50
|
-
mlquantify-0.1.
|
|
51
|
-
mlquantify-0.1.
|
|
52
|
-
mlquantify-0.1.
|
|
53
|
-
mlquantify-0.1.
|
|
50
|
+
mlquantify-0.1.16.dist-info/METADATA,sha256=RZWNq8k48KnN4PYd-6Iw5mv-qS6bAVL2tc6zg9cMqN0,4701
|
|
51
|
+
mlquantify-0.1.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
52
|
+
mlquantify-0.1.16.dist-info/top_level.txt,sha256=tGEkYkbbFElwULvqENjam3u1uXtyC1J9dRmibsq8_n0,11
|
|
53
|
+
mlquantify-0.1.16.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|