You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Enhance histogram functionality and CLI integration
- Introduced function to choose the best histogram based on max_bins or optimal selection criteria.
- Updated function to filter input data by range and utilize the new selection logic.
- Refactored to always return a list of histogram results, removing the and parameters.
- Modified to always return all granularities of histogram results.
- Improved CSV reading logic in for better type handling.
- Updated function to align with new histogram computation logic.
- Enhanced tests to verify histogram filtering by range and validate the structure of returned results.
Copy file name to clipboardExpand all lines: docs/API.md
+31-42Lines changed: 31 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,16 +29,16 @@ khisto.histogram(
29
29
30
30
Compute an optimal histogram using the Khiops binning algorithm.
31
31
32
-
This function is designed as a drop-in replacement for `numpy.histogram`, providing automatic optimal binning instead of fixed-width bins.
32
+
Drop-in replacement for [`numpy.histogram`](https://numpy.org/doc/stable/reference/generated/numpy.histogram.html), using optimal binning instead of fixed-width bins.
33
33
34
34
#### Parameters
35
35
36
36
| Parameter | Type | Default | Description |
37
37
|-----------|------|---------|-------------|
38
38
|`a`|`ArrayLike`| required | Input data. The histogram is computed over the flattened array. |
39
-
|`range`|`tuple[float, float]`|`None`|The lower and upper range of the bins. If not provided, range is `(a.min(), a.max())`. Values outside the range are ignored. |
40
-
|`max_bins`|`int`|`None`| Maximum number of bins. If not provided, the algorithm determines the optimal number. |
41
-
|`density`|`bool`|`False`| If `False`, the result contains the number of samples in each bin. If `True`, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1. |
39
+
|`range`|`tuple[float, float]`|`None`|Lower and upper range of the bins. Values outside are ignored. |
40
+
|`max_bins`|`int`|`None`| Maximum number of bins. If not provided, the optimal number is determined automatically. |
41
+
|`density`|`bool`|`False`| If `True`, return probability density values; otherwise return counts. |
42
42
43
43
#### Returns
44
44
@@ -47,6 +47,10 @@ This function is designed as a drop-in replacement for `numpy.histogram`, provid
47
47
|`hist`|`NDArray[np.floating]`| The values of the histogram. |
48
48
|`bin_edges`|`NDArray[np.floating]`| Array of length `len(hist) + 1` containing the bin edges. |
49
49
50
+
#### See Also
51
+
52
+
-[`numpy.histogram`](https://numpy.org/doc/stable/reference/generated/numpy.histogram.html) — NumPy's standard histogram function.
53
+
50
54
#### Examples
51
55
52
56
Basic usage:
@@ -90,28 +94,26 @@ The core API provides direct access to the Khiops histogram computation with det
Compute an optimal histogram using the Khiops binning algorithm.
100
+
Compute optimal histograms at all granularity levels using the Khiops binning algorithm.
100
101
101
102
#### Parameters
102
103
103
104
| Parameter | Type | Default | Description |
104
105
|-----------|------|---------|-------------|
105
106
|`x`|`ArrayLike`| required | Input data array. |
106
-
|`max_bins`|`int`|`None`| Maximum number of bins for the histogram. |
107
-
|`range`|`tuple[float, float]`|`None`| The range `(min, max)` over which to compute the histogram. Values outside this range are ignored. |
108
-
|`return_all`|`bool`|`False`| If `True`, return all granularity levels computed by the algorithm. If `False`, return only the optimal histogram. |
109
107
110
108
#### Returns
111
109
112
110
| Return | Type | Description |
113
111
|--------|------|-------------|
114
-
|`result`|`HistogramResult` or `list[HistogramResult]`| If `return_all=False`, returns a single `HistogramResult` for the optimal histogram. If `return_all=True`, returns a list of `HistogramResult` objects for all granularity levels. |
112
+
|`results`|`list[HistogramResult]`| List of `HistogramResult` objects for all granularity levels, from coarsest to finest. |
This function is designed to work similarly to `matplotlib.pyplot.hist`, but uses Khiops optimal binning.
217
+
Drop-in replacement for [`matplotlib.pyplot.hist`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html) using Khisto's optimal binning algorithm.
228
218
229
219
#### Parameters
230
220
231
221
| Parameter | Type | Default | Description |
232
222
|-----------|------|---------|-------------|
233
223
|`x`|`ArrayLike`| required | Input data. |
234
-
|`range`|`tuple[float, float]`|`None`| The lower and upper range of the bins. |
235
-
|`max_bins`|`int`|`None`| Maximum number of bins. |
236
-
|`density`|`bool`|`False`| If `True`, plot probability density instead of counts. |
237
-
|`histtype`|`str`|`"bar"`| Type of histogram: `"bar"`, `"step"`, or `"stepfilled"`. |
238
-
|`orientation`|`str`|`"vertical"`|`"vertical"` or `"horizontal"`. |
239
-
|`log`|`bool`|`False`| If `True`, set log scale on the value axis. |
240
-
|`color`|`str`|`None`| Color of the histogram. |
241
-
|`label`|`str`|`None`| Label for legend. |
242
-
|`ax`|`Axes`|`None`| Matplotlib axes to plot on. If `None`, uses current axes. |
243
-
|`**kwargs`||| Additional arguments passed to matplotlib's `bar` or `stairs`. |
224
+
|`range`|`tuple[float, float]`|`None`| Lower and upper range of the bins. Values outside are ignored. |
225
+
|`max_bins`|`int`|`None`| Maximum number of bins. If `None`, uses optimal binning. |
226
+
|`ax`|`Axes`|`None`| Axes to plot on. If `None`, uses current axes. |
227
+
|`**kwargs`||| Other parameters passed to matplotlib. See [`matplotlib.pyplot.hist`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html). |
244
228
245
229
#### Returns
246
230
@@ -250,6 +234,11 @@ This function is designed to work similarly to `matplotlib.pyplot.hist`, but use
250
234
|`bins`|`NDArray[np.floating]`| The bin edges. |
251
235
|`patches`|`Any`| Container of individual artists (bars or StepPatch). |
252
236
237
+
#### See Also
238
+
239
+
-[`matplotlib.pyplot.hist`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html) — Full documentation of supported parameters.
0 commit comments