mlquantify 0.1.19__py3-none-any.whl → 0.1.20__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.
@@ -696,59 +696,67 @@ class QuaDapt(MetaquantifierMixin, BaseQuantifier):
696
696
 
697
697
  def aggregate(self, predictions, train_y_values):
698
698
 
699
- pos_predictions = predictions[:, 1]
700
- m = self._get_best_merging_factor(pos_predictions)
699
+ prevalence, _, _ = self.best_mixture(predictions)
700
+ prevalences = np.asarray([1-prevalence, prevalence])
701
701
 
702
702
  self.classes = self.classes if hasattr(self, 'classes') else np.unique(train_y_values)
703
-
704
- moss_scores, moss_labels = self.MoSS(1000, 0.5, m)
705
-
706
- prevalences = self.quantifier.aggregate(predictions,
707
- moss_scores,
708
- moss_labels)
709
703
 
710
- prevalences = {self.classes[i]: v for i, v in enumerate(prevalences.values())}
704
+ prevalences = validate_prevalences(self, prevalences, self.classes)
711
705
  return prevalences
712
706
 
713
707
 
714
- def _get_best_merging_factor(self, predictions):
708
+ def best_mixture(self, predictions):
709
+ predictions = predictions[:, 1]
715
710
 
716
711
  MF = np.atleast_1d(np.round(self.merging_factors, 2)).astype(float)
717
712
 
718
713
  distances = []
714
+ alphas = []
719
715
 
720
716
  for mf in MF:
721
- scores, labels = self.MoSS(1000, 0.5, mf)
717
+ scores, labels = self.MoSS(n=1000, alpha=0.5, merging_factor=mf)
722
718
  pos_scores = scores[labels == 1][:, 1]
723
719
  neg_scores = scores[labels == 0][:, 1]
720
+
721
+ if self.measure in ["hellinger", "topsoe", "probsymm"]:
722
+ method = DyS(measure=self.measure)
723
+ elif self.measure == "sord":
724
+ method = SORD()
724
725
 
725
- best_distance = self._get_best_distance(predictions, pos_scores, neg_scores)
726
+ alpha, distance = method.best_mixture(predictions, pos_scores, neg_scores)
726
727
 
727
- distances.append(best_distance)
728
+ distances.append(distance)
729
+ alphas.append(alpha)
728
730
 
729
731
  best_m = MF[np.argmin(distances)]
730
- return best_m
732
+ best_alpha = alphas[np.argmin(distances)]
733
+ best_distance = np.min(distances)
734
+ return best_alpha, best_distance, best_m
731
735
 
732
- def _get_best_distance(self, predictions, pos_scores, neg_scores):
733
-
734
- if self.measure in ["hellinger", "topsoe", "probsymm"]:
735
- method = DyS(measure=self.measure)
736
- elif self.measure == "sord":
737
- method = SORD()
736
+ def get_best_distance(self, predictions):
738
737
 
739
- best_distance = method.get_best_distance(predictions, pos_scores, neg_scores)
740
- return best_distance
738
+ _, distance, _= self.get_best_merging_factor(predictions)
739
+
740
+ return distance
741
741
 
742
742
 
743
743
  @classmethod
744
- def MoSS(cls, n, alpha, m):
744
+ def MoSS(cls, n, alpha, merging_factor):
745
745
  r"""Model for Score Simulation
746
746
 
747
- MoSS has three key parameters:
748
- (I) the number of observations `n`;
749
- (II) the class proportion `\alpha`, which defines the prevalence of the positive class;
750
- (III) the merging factor :math:`m`, which controls the overlap between positive and negative score distributions
751
- (where :math:`m=0` represents easily separable classes and :math:`m=1` represents highly overlapping ones).
747
+ Parameters
748
+ ----------
749
+ n : int
750
+ Number of observations.
751
+ alpha : float
752
+ Class proportion, which defines the prevalence of the positive class.
753
+ m : float
754
+ Merging factor, which controls the overlap between positive and negative score distributions.
755
+
756
+ Returns
757
+ -------
758
+ tuple
759
+ Tuple of score and label arrays.
752
760
 
753
761
  .. math::
754
762
 
@@ -776,9 +784,9 @@ class QuaDapt(MetaquantifierMixin, BaseQuantifier):
776
784
  n_neg = n - n_pos
777
785
 
778
786
  # Scores positivos
779
- p_score = np.random.uniform(size=n_pos) ** m
787
+ p_score = np.random.uniform(size=n_pos) ** merging_factor
780
788
  # Scores negativos
781
- n_score = 1 - (np.random.uniform(size=n_neg) ** m)
789
+ n_score = 1 - (np.random.uniform(size=n_neg) ** merging_factor)
782
790
 
783
791
  # Construção dos arrays de features (duas colunas iguais)
784
792
  moss = np.column_stack(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mlquantify
3
- Version: 0.1.19
3
+ Version: 0.1.20
4
4
  Summary: Quantification Library
5
5
  Home-page: https://github.com/luizfernandolj/QuantifyML/tree/master
6
6
  Maintainer: Luiz Fernando Luth Junior
@@ -13,7 +13,7 @@ mlquantify/likelihood/__init__.py,sha256=3dC5uregNmquUKz0r0-3aPspfjZjKGn3TRBoZPO
13
13
  mlquantify/likelihood/_base.py,sha256=seu_Vb58QttcGbFjHKAplMYGZcVbIHqkyTXEK2cax9A,5830
14
14
  mlquantify/likelihood/_classes.py,sha256=PZ31cAwO8q5X3O2_oSmQ1FM6bY4EsB8hWEcAgcEmWXQ,14731
15
15
  mlquantify/meta/__init__.py,sha256=GzdGw4ky_kmd5VNWiLBULy06IdN_MLCDAuJKbnMOx4s,62
16
- mlquantify/meta/_classes.py,sha256=RKEVghPMBlyv516xrUtTyUkHvC2-5IsTUO_oVwAt3Gw,30930
16
+ mlquantify/meta/_classes.py,sha256=0o3LBPGc-8znwJL0_TFo9zXjHrXqXc0QIPpzwaghFKQ,30898
17
17
  mlquantify/metrics/__init__.py,sha256=3bzzjSYTgrZIJsfAgJidQlB-bnjInwVYUvJ34bPhZxY,186
18
18
  mlquantify/metrics/_oq.py,sha256=koXDKeHWksl_vHpZuhc2pAps8wvu_MOgEztlSr04MmE,3544
19
19
  mlquantify/metrics/_rq.py,sha256=3yiEmGaRAGpzL29Et3tNqkJ3RMsLXwUX3uL9RoIgi40,3034
@@ -47,7 +47,7 @@ mlquantify/utils/_sampling.py,sha256=3W0vUuvLvoYrt-BZpSM0HM1XJEZr0XYIdkOcUP5hp-8
47
47
  mlquantify/utils/_tags.py,sha256=Rz78TLpxgVxBKS0mKTlC9Qo_kn6HaEwVKNXh8pxFT7M,1095
48
48
  mlquantify/utils/_validation.py,sha256=zn4OHfa704YBaPKskhiThUG7wS5fvDoHBpcEgb1i8qM,18078
49
49
  mlquantify/utils/prevalence.py,sha256=LG-KXJ5Eb4w26WMpu4PoBpxMSHaqrmTQqdRlyqNRJ1o,2020
50
- mlquantify-0.1.19.dist-info/METADATA,sha256=nQ0BqrdrpxbBTHhFh6p2M9qXqQsehRAdqIB5cpNbr1s,4701
51
- mlquantify-0.1.19.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
52
- mlquantify-0.1.19.dist-info/top_level.txt,sha256=tGEkYkbbFElwULvqENjam3u1uXtyC1J9dRmibsq8_n0,11
53
- mlquantify-0.1.19.dist-info/RECORD,,
50
+ mlquantify-0.1.20.dist-info/METADATA,sha256=VTVfeUzcWUpxdiPLHxr1wlkzfpyRAZ5ABhuAJksBg9E,4701
51
+ mlquantify-0.1.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
52
+ mlquantify-0.1.20.dist-info/top_level.txt,sha256=tGEkYkbbFElwULvqENjam3u1uXtyC1J9dRmibsq8_n0,11
53
+ mlquantify-0.1.20.dist-info/RECORD,,