khalib 0.4__tar.gz → 0.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: khalib
3
- Version: 0.4
3
+ Version: 0.6
4
4
  Summary: Classifier Calibration with Khiops
5
5
  Author-email: Felipe Olmos <luisfelipe.olmosmarchant@orange.com>
6
6
  License-Expression: BSD-3-Clause
@@ -26,7 +26,7 @@ Classifier: Programming Language :: Python :: 3.14
26
26
  Requires-Python: >=3.11
27
27
  Description-Content-Type: text/markdown
28
28
  License-File: LICENSE.md
29
- Requires-Dist: khiops>=11.0.0.0
29
+ Requires-Dist: khiops>=11.0.1.0
30
30
  Requires-Dist: numpy>=2.0.0
31
31
  Requires-Dist: scikit-learn>=1.5.0
32
32
  Requires-Dist: matplotlib>=3.9.0
@@ -57,13 +57,9 @@ See the [documentation][khalib-docs] for more information.
57
57
  <!-- start-install -->
58
58
  ## Installation
59
59
 
60
- - [Install Khiops][khiops-setup]
61
- - Install the `khalib` python library:
62
-
63
60
  ```sh
64
61
  pip install khalib
65
62
  ```
66
- [khiops-setup]: https://khiops.org/setup/
67
63
 
68
64
  <!-- end-install -->
69
65
 
@@ -23,13 +23,9 @@ See the [documentation][khalib-docs] for more information.
23
23
  <!-- start-install -->
24
24
  ## Installation
25
25
 
26
- - [Install Khiops][khiops-setup]
27
- - Install the `khalib` python library:
28
-
29
26
  ```sh
30
27
  pip install khalib
31
28
  ```
32
- [khiops-setup]: https://khiops.org/setup/
33
29
 
34
30
  <!-- end-install -->
35
31
 
@@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "khalib"
7
- version = "0.4"
7
+ version = "0.6"
8
8
  description = "Classifier Calibration with Khiops"
9
9
  authors = [{ name = "Felipe Olmos", email = "luisfelipe.olmosmarchant@orange.com" }]
10
10
  requires-python = ">=3.11"
11
11
  dependencies = [
12
- "khiops>=11.0.0.0",
12
+ "khiops>=11.0.1.0",
13
13
  "numpy>=2.0.0",
14
14
  "scikit-learn>=1.5.0",
15
15
  "matplotlib>=3.9.0",
@@ -304,10 +304,8 @@ class Histogram:
304
304
  y_indexes = le.transform(y)
305
305
  x_bin_indexes = (
306
306
  np.searchsorted(breakpoints[:-1], x, side="left") - 1
307
- ).reshape(1, -1)
307
+ ).reshape(-1)
308
308
  x_bin_indexes[x_bin_indexes < 0] = 0
309
- # Note: reshape is needed for the 1-column matrix case if not the
310
- # iterator below does not work
311
309
 
312
310
  # Compute the target frequencies
313
311
  target_freqs = [[0 for _ in le.classes_] for _ in breakpoints[:-1]]
@@ -315,7 +313,7 @@ class Histogram:
315
313
  [x_bin_indexes, y_indexes]
316
314
  ):
317
315
  target_freqs[y_score_bin_index][y_index] += 1
318
- target_freqs = [tuple(freqs) for freqs in target_freqs]
316
+ target_freqs = [tuple(tf) for tf in target_freqs]
319
317
  # Otherwise there is just one interval
320
318
  else:
321
319
  # Non-informative variable: histogram with only the bin (min, max)
@@ -417,8 +415,10 @@ class Histogram:
417
415
  f"the number of classes: {len(tfreqs)} != {len(self.classes)}."
418
416
  )
419
417
  if sum(tfreqs) != self.freqs[i]:
420
- f"`target_freqs` at bin index {i} sums different from the bin "
421
- f"frequency: {sum(tfreqs)} != {self.freqs[i]}"
418
+ raise ValueError(
419
+ f"`target_freqs` at bin index {i} sums different from the bin "
420
+ f"frequency: {sum(tfreqs)} != {self.freqs[i]}"
421
+ )
422
422
 
423
423
  # Initialize the densities and target probabilities
424
424
  self.densities = [
@@ -797,11 +797,6 @@ class KhalibClassifier(ClassifierMixin, MetaEstimatorMixin, BaseEstimator):
797
797
  for k in range(n_classes)
798
798
  ]
799
799
 
800
- calibrated_probas = np.empty(scores.shape)
801
- for k, histogram in enumerate(self.histograms_):
802
- calibrated_probas[:, k] = calibrate_binary(
803
- scores[:, k], histogram, only_positive=True
804
- )
805
800
  return self
806
801
 
807
802
  def predict_proba(self, X): # noqa: N803
@@ -913,7 +908,7 @@ def build_reliability_diagram(
913
908
  *Density plot only:* If the log-difference between the maximal and minimal
914
909
  positive density values is larger than 'log_plot_threshold' then the density
915
910
  plot uses a log scale in the y-axis.
916
- min_density_bar_width : float, default=5.0e-03
911
+ min_density_bar_width : float, default=2.5e-03
917
912
  *Density plot only:* If a bin of the scores' unsupervised histogram has a width
918
913
  lower than 'min_density_bar_width' then it is plotted as having a width of
919
914
  'min_density_bar_width'.
@@ -935,7 +930,7 @@ def build_reliability_diagram(
935
930
  )
936
931
  if len(y.shape) > 1:
937
932
  raise ValueError(
938
- f"'y_scores' must be a 1-D array-like object, but its shape is {y.shape}"
933
+ f"'y' must be a 1-D array-like object, but its shape is {y.shape}"
939
934
  )
940
935
  if dirac_threshold <= 0.0:
941
936
  raise ValueError("'dirac_threshold' must be positive")
@@ -1049,7 +1044,7 @@ def build_reliability_diagram(
1049
1044
  )
1050
1045
  if freq > 0
1051
1046
  ]
1052
- density_bar_log_range = None
1047
+ density_bar_log_range = 0
1053
1048
  if density_bar_heights:
1054
1049
  density_bar_log_range = math.log10(max(density_bar_heights)) - math.log10(
1055
1050
  min(density_bar_heights)
@@ -1078,10 +1073,19 @@ def compute_dirac_indexes(uhist, dirac_threshold):
1078
1073
 
1079
1074
  We declare a dirac mass bin if:
1080
1075
 
1081
- - it is surrounded by empty bins.
1076
+ - it is surrounded by empty bins or if it is the only one
1082
1077
  - its length is less than ``dirac_threshold``
1083
1078
 
1084
1079
  """
1080
+
1081
+ # Early return for just one bin
1082
+ if len(uhist.freqs) == 1:
1083
+ if uhist.bins[0][1] - uhist.bins[0][0] < dirac_threshold:
1084
+ return [True]
1085
+ else:
1086
+ return [False]
1087
+
1088
+ # More than one bin
1085
1089
  dirac_indexes = []
1086
1090
  if (
1087
1091
  len(uhist.freqs) > 1
@@ -1102,7 +1106,7 @@ def compute_dirac_indexes(uhist, dirac_threshold):
1102
1106
  else:
1103
1107
  dirac_indexes.append(False)
1104
1108
  if (
1105
- len(uhist.freqs) > 2
1109
+ len(uhist.freqs) > 1
1106
1110
  and uhist.freqs[-2] == 0
1107
1111
  and (uhist.bins[-1][1] - uhist.bins[-1][0] < dirac_threshold)
1108
1112
  ):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: khalib
3
- Version: 0.4
3
+ Version: 0.6
4
4
  Summary: Classifier Calibration with Khiops
5
5
  Author-email: Felipe Olmos <luisfelipe.olmosmarchant@orange.com>
6
6
  License-Expression: BSD-3-Clause
@@ -26,7 +26,7 @@ Classifier: Programming Language :: Python :: 3.14
26
26
  Requires-Python: >=3.11
27
27
  Description-Content-Type: text/markdown
28
28
  License-File: LICENSE.md
29
- Requires-Dist: khiops>=11.0.0.0
29
+ Requires-Dist: khiops>=11.0.1.0
30
30
  Requires-Dist: numpy>=2.0.0
31
31
  Requires-Dist: scikit-learn>=1.5.0
32
32
  Requires-Dist: matplotlib>=3.9.0
@@ -57,13 +57,9 @@ See the [documentation][khalib-docs] for more information.
57
57
  <!-- start-install -->
58
58
  ## Installation
59
59
 
60
- - [Install Khiops][khiops-setup]
61
- - Install the `khalib` python library:
62
-
63
60
  ```sh
64
61
  pip install khalib
65
62
  ```
66
- [khiops-setup]: https://khiops.org/setup/
67
63
 
68
64
  <!-- end-install -->
69
65
 
@@ -1,4 +1,4 @@
1
- khiops>=11.0.0.0
1
+ khiops>=11.0.1.0
2
2
  numpy>=2.0.0
3
3
  scikit-learn>=1.5.0
4
4
  matplotlib>=3.9.0
File without changes
File without changes
File without changes