mlquantify 0.1.13__tar.gz → 0.1.15__tar.gz
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-0.1.13/mlquantify.egg-info → mlquantify-0.1.15}/PKG-INFO +1 -1
- mlquantify-0.1.15/VERSION.txt +1 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/adjust_counting/_adjustment.py +20 -13
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/adjust_counting/_base.py +5 -6
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/adjust_counting/_counting.py +5 -3
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/meta/_classes.py +2 -2
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_validation.py +5 -5
- {mlquantify-0.1.13 → mlquantify-0.1.15/mlquantify.egg-info}/PKG-INFO +1 -1
- mlquantify-0.1.13/VERSION.txt +0 -1
- {mlquantify-0.1.13 → mlquantify-0.1.15}/MANIFEST.in +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/README.md +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/adjust_counting/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/adjust_counting/_utils.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/base.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/base_aggregative.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/calibration.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/confidence.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/likelihood/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/likelihood/_base.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/likelihood/_classes.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/meta/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/metrics/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/metrics/_oq.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/metrics/_rq.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/metrics/_slq.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/mixture/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/mixture/_base.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/mixture/_classes.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/mixture/_utils.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/model_selection/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/model_selection/_protocol.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/model_selection/_search.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/model_selection/_split.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/multiclass.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/neighbors/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/neighbors/_base.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/neighbors/_classes.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/neighbors/_classification.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/neighbors/_kde.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/neighbors/_utils.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/neural/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/__init__.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_artificial.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_constraints.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_context.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_decorators.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_exceptions.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_get_scores.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_load.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_parallel.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_random.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_sampling.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/_tags.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify/utils/prevalence.py +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify.egg-info/SOURCES.txt +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify.egg-info/dependency_links.txt +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify.egg-info/requires.txt +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/mlquantify.egg-info/top_level.txt +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/setup.cfg +0 -0
- {mlquantify-0.1.13 → mlquantify-0.1.15}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.15
|
|
@@ -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
|
|
@@ -104,7 +105,7 @@ class ThresholdAdjustment(SoftLearnerQMixin, BaseAdjustCount):
|
|
|
104
105
|
thresholds, tprs, fprs = evaluate_thresholds(train_y_values, positive_scores)
|
|
105
106
|
threshold, tpr, fpr = self.get_best_threshold(thresholds, tprs, fprs)
|
|
106
107
|
|
|
107
|
-
cc_predictions = CC(threshold).aggregate(predictions)[1]
|
|
108
|
+
cc_predictions = CC(threshold=threshold).aggregate(predictions, train_y_values)[1]
|
|
108
109
|
|
|
109
110
|
if tpr - fpr == 0:
|
|
110
111
|
prevalence = cc_predictions
|
|
@@ -208,7 +209,7 @@ class MatrixAdjustment(BaseAdjustCount):
|
|
|
208
209
|
prevs_estim = self._get_estimations(predictions > priors)
|
|
209
210
|
prevalence = self._solve_optimization(prevs_estim, priors)
|
|
210
211
|
else:
|
|
211
|
-
self.CM = self._compute_confusion_matrix(train_y_pred)
|
|
212
|
+
self.CM = self._compute_confusion_matrix(train_y_pred, train_y_values)
|
|
212
213
|
prevs_estim = self._get_estimations(predictions)
|
|
213
214
|
prevalence = self._solve_linear(prevs_estim)
|
|
214
215
|
|
|
@@ -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
|
|
|
@@ -514,7 +521,7 @@ class X_method(ThresholdAdjustment):
|
|
|
514
521
|
*ECML*, pp. 564-575.
|
|
515
522
|
"""
|
|
516
523
|
def get_best_threshold(self, thresholds, tprs, fprs):
|
|
517
|
-
idx = np.argmin(np.abs(1
|
|
524
|
+
idx = np.argmin(np.abs((1-tprs) - fprs))
|
|
518
525
|
return thresholds[idx], tprs[idx], fprs[idx]
|
|
519
526
|
|
|
520
527
|
|
|
@@ -601,7 +608,7 @@ class MS(ThresholdAdjustment):
|
|
|
601
608
|
|
|
602
609
|
prevs = []
|
|
603
610
|
for thr, tpr, fpr in zip(thresholds, tprs, fprs):
|
|
604
|
-
cc_predictions = CC(thr).aggregate(predictions)
|
|
611
|
+
cc_predictions = CC(threshold=thr).aggregate(predictions, train_y_values)
|
|
605
612
|
cc_predictions = cc_predictions[1]
|
|
606
613
|
|
|
607
614
|
if tpr - fpr == 0:
|
|
@@ -204,7 +204,7 @@ class BaseAdjustCount(AggregationMixin, BaseQuantifier):
|
|
|
204
204
|
self.learner = learner
|
|
205
205
|
|
|
206
206
|
@_fit_context(prefer_skip_nested_validation=True)
|
|
207
|
-
def fit(self, X, y, learner_fitted=False):
|
|
207
|
+
def fit(self, X, y, learner_fitted=False, cv=10, stratified=True, random_state=None, shuffle=True):
|
|
208
208
|
"""Fit the quantifier using the provided data and learner."""
|
|
209
209
|
X, y = validate_data(self, X, y)
|
|
210
210
|
validate_y(self, y)
|
|
@@ -220,10 +220,10 @@ class BaseAdjustCount(AggregationMixin, BaseQuantifier):
|
|
|
220
220
|
X,
|
|
221
221
|
y,
|
|
222
222
|
function=learner_function,
|
|
223
|
-
cv=
|
|
224
|
-
stratified=
|
|
225
|
-
random_state=
|
|
226
|
-
shuffle=
|
|
223
|
+
cv=cv,
|
|
224
|
+
stratified=stratified,
|
|
225
|
+
random_state=random_state,
|
|
226
|
+
shuffle=shuffle
|
|
227
227
|
)
|
|
228
228
|
|
|
229
229
|
self.train_predictions = train_predictions
|
|
@@ -241,7 +241,6 @@ class BaseAdjustCount(AggregationMixin, BaseQuantifier):
|
|
|
241
241
|
self.classes_ = check_classes_attribute(self, np.unique(y_train_values))
|
|
242
242
|
|
|
243
243
|
predictions = validate_predictions(self, predictions)
|
|
244
|
-
train_predictions = validate_predictions(self, train_predictions)
|
|
245
244
|
|
|
246
245
|
prevalences = self._adjust(predictions, train_predictions, y_train_values)
|
|
247
246
|
prevalences = validate_prevalences(self, prevalences, self.classes_)
|
|
@@ -75,10 +75,12 @@ class CC(CrispLearnerQMixin, BaseCount):
|
|
|
75
75
|
super().__init__(learner=learner)
|
|
76
76
|
self.threshold = threshold
|
|
77
77
|
|
|
78
|
-
def aggregate(self, predictions):
|
|
79
|
-
predictions = validate_predictions(self, predictions)
|
|
78
|
+
def aggregate(self, predictions, train_y_values=None):
|
|
79
|
+
predictions = validate_predictions(self, predictions, self.threshold)
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
if train_y_values is None:
|
|
82
|
+
train_y_values = np.unique(predictions)
|
|
83
|
+
self.classes_ = check_classes_attribute(self, np.unique(train_y_values))
|
|
82
84
|
class_counts = np.array([np.count_nonzero(predictions == _class) for _class in self.classes_])
|
|
83
85
|
prevalences = class_counts / len(predictions)
|
|
84
86
|
|
|
@@ -776,9 +776,9 @@ class QuaDapt(MetaquantifierMixin, BaseQuantifier):
|
|
|
776
776
|
n_neg = n - n_pos
|
|
777
777
|
|
|
778
778
|
# Scores positivos
|
|
779
|
-
p_score = np.random.uniform(size=n_pos) **
|
|
779
|
+
p_score = np.random.uniform(size=n_pos) ** m
|
|
780
780
|
# Scores negativos
|
|
781
|
-
n_score = 1 - (np.random.uniform(size=n_neg) **
|
|
781
|
+
n_score = 1 - (np.random.uniform(size=n_neg) ** m)
|
|
782
782
|
|
|
783
783
|
# Construção dos arrays de features (duas colunas iguais)
|
|
784
784
|
moss = np.column_stack(
|
|
@@ -97,22 +97,22 @@ def validate_y(quantifier: Any, y: np.ndarray) -> None:
|
|
|
97
97
|
def _get_valid_crisp_predictions(predictions, threshold=0.5):
|
|
98
98
|
predictions = np.asarray(predictions)
|
|
99
99
|
|
|
100
|
-
dimensions = predictions.
|
|
100
|
+
dimensions = predictions.ndim
|
|
101
101
|
|
|
102
102
|
if dimensions > 2:
|
|
103
103
|
predictions = np.argmax(predictions, axis=1)
|
|
104
104
|
elif dimensions == 2:
|
|
105
|
-
predictions = (predictions[:, 1]
|
|
105
|
+
predictions = (predictions[:, 1] >= threshold).astype(int)
|
|
106
106
|
elif dimensions == 1:
|
|
107
107
|
if np.issubdtype(predictions.dtype, np.floating):
|
|
108
|
-
predictions = (predictions
|
|
108
|
+
predictions = (predictions >= threshold).astype(int)
|
|
109
109
|
else:
|
|
110
110
|
raise ValueError(f"Predictions array has an invalid number of dimensions. Expected 1 or more dimensions, got {predictions.ndim}.")
|
|
111
111
|
|
|
112
112
|
return predictions
|
|
113
113
|
|
|
114
114
|
|
|
115
|
-
def validate_predictions(quantifier: Any, predictions: np.ndarray) ->
|
|
115
|
+
def validate_predictions(quantifier: Any, predictions: np.ndarray, threshold: float = 0.5) -> np.ndarray:
|
|
116
116
|
"""
|
|
117
117
|
Validate predictions using the quantifier's declared output tags.
|
|
118
118
|
Raises InputValidationError if inconsistent with tags.
|
|
@@ -132,7 +132,7 @@ def validate_predictions(quantifier: Any, predictions: np.ndarray) -> None:
|
|
|
132
132
|
f"Soft predictions for {quantifier.__class__.__name__} must be float, got dtype {predictions.dtype}."
|
|
133
133
|
)
|
|
134
134
|
elif estimator_type == "crisp" and np.issubdtype(predictions.dtype, np.floating):
|
|
135
|
-
predictions = _get_valid_crisp_predictions(predictions)
|
|
135
|
+
predictions = _get_valid_crisp_predictions(predictions, threshold)
|
|
136
136
|
return predictions
|
|
137
137
|
|
|
138
138
|
|
mlquantify-0.1.13/VERSION.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.1.13
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|