Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Setup Just
uses: extractions/setup-just@v3
with:
enable-cache: true
- name: Run pre-commit
run: just pre-commit
run: uvx pre-commit run --all-files --verbose
11 changes: 5 additions & 6 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ jobs:
- uses: actions/checkout@v4
- name: Setup uv
uses: astral-sh/setup-uv@v6
- name: Setup Python
run: uv python install
with:
python-version: '3.14'
enable-cache: true
- name: Setup just
uses: extractions/setup-just@v3
- name: Setup Khiops
run: |
sudo apt-get update -y && sudo apt-get install wget lsb-release -y
CODENAME=$(lsb_release -cs)
TEMP_DEB="$(mktemp)"
wget -O "$TEMP_DEB" "https://github.com/KhiopsML/khiops/releases/download/11.0.0-b.0/khiops-core-openmpi_11.0.0-b.0-1-${CODENAME}.amd64.deb"
sudo dpkg -i "$TEMP_DEB" || sudo apt-get -f -y install
wget -O "./khiops.deb" "https://github.com/KhiopsML/khiops/releases/download/11.0.0/khiops-core-openmpi_11.0.0-1-$(lsb_release -cs).amd64.deb"
sudo dpkg -i "./khiops.deb" || sudo apt-get -f -y install
- name: Build docs
run: |
mkdir docs/_static
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Package
on:
workflow_dispatch:
inputs:
pypi-target:
type: choice
default: no-op
options: [no-op, testpypi, pypi]
description: PyPI Target
pull_request:

# Cancel any ongoing run of this workflow on the same PR or ref
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup uv
uses: astral-sh/setup-uv@v6
with:
python-version: '3.14'
enable-cache: true
- name: Build Package
run: |
uv build --sdist
- name: Upload package artifact
uses: actions/upload-artifact@v6
with:
name: pip-package
path: dist/
publish-pypi:
if: inputs.pypi-target == 'pypi' && github.ref_type == 'tag' && github.repository_owner == 'KhiopsLab'
needs: [build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/khalib
permissions:
id-token: write
steps:
- name: Download package artifact
uses: actions/download-artifact@v6
with:
name: pip-package
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-testpypi:
if: inputs.pypi-target == 'testpypi' && github.ref_type == 'tag' && github.repository_owner == 'KhiopsLab'
needs: [build]
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/khalib
permissions:
id-token: write
steps:
- name: Download package artifact
uses: actions/download-artifact@v6
with:
name: pip-package
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
13 changes: 8 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- 'src/**'
- .github/workflows/tests.yaml

# Cancel any ongoing run of this workflow on the same PR or ref
concurrency:
Expand All @@ -24,15 +25,17 @@ jobs:
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python
run: uv python install
enable-cache: true
- name: Setup just
uses: extractions/setup-just@v3
- name: Install Miniforge
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
miniforge-version: latest
conda-remove-defaults: true
- name: Install khiops
run: conda install --quiet --yes --name test khiops-core=11.0.0b.0
- name: Install Khiops
run: conda install --quiet --yes --name test khiops-core>=11.0.0
- name: Run tests
run: conda run --name test uv run pytest src/tests
# We run with `conda` so we find the khiops executables installed in the conda env
run: conda run --name test just test
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.4
rev: v0.14.10
hooks:
- id: ruff-check
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/mwouts/jupytext
rev: v1.17.3
rev: v1.19.0.dev0
hooks:
- id: jupytext
args: [--update, --from, py:percent, --to, notebook]
files: docs/quickstart.py
- repo: https://github.com/rhysd/actionlint
rev: v1.7.8
rev: v1.7.9
hooks:
- id: actionlint
name: actionlint
Expand Down
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Changelog

## [0.2] - 2025-12-26

### Changed
- Update Khiops dependency to version 11.

## [0.1] - 2025-10-17

### Added
- `KhalibClassifier` class
- `calibration_error` function
- `build_reliability_diagram` function

[Unreleased]: https://github.com/yourusername/yourproject/compare/0.1...HEAD
[1.0.0]: https://github.com/yourusername/yourproject/releases/tag/0.1
[Unreleased]: https://github.com/yourusername/yourproject/compare/0.2...HEAD
[0.2]: https://github.com/yourusername/yourproject/compare/0.1...0.2
[0.1]: https://github.com/yourusername/yourproject/releases/tag/0.1
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@ suite.

## Features
- `KhalibClassifier`: A scikit-learn estimator to calibrate classifiers with a similar interface
fashion as [CalibratedClassifierCV][sk-calclf].
as [CalibratedClassifierCV][sk-calclf].
- `calibration_error` : A function to estimate the Estimated Calibration Error (ECE).
- `build_reliability_diagram` : A function that builds a reliability diagram.
- `build_reliability_diagram` : A function to build a reliability diagram.

These features are based on Khiops's non-parametric supervised histograms, so there is no need to
specify the number and width of the bins, as they are automatically estimated from data.

[khiops-org]: https://khiops.org
[sk-calclf]: https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV.html

<!-- end-summary -->

See the [documentation][khalib-docs] for more information.

<!-- start-install -->
## Installation

*Note: We'll improve this installation procedure soon!*

- Make sure you have installed [Khiops 11 Beta][khiops11-setup]
- Execute
- [Install Khiops][khiops-setup]
- Install the `khalib` python library:

```bash
pip install https://github.com/KhiopsLab/khalib/archive/refs/tags/0.1.zip
```sh
pip install khalib
```
[khiops-setup]: https://khiops.org/setup/

<!-- end-install -->

Expand All @@ -37,8 +39,4 @@ pip install https://github.com/KhiopsLab/khalib/archive/refs/tags/0.1.zip
See https://khiopslab.github.io/khalib/


[khiops-org]: https://khiops.org
[khiops11-setup]: https://khiops.org/11.0.0-b.0/setup/
[sk-calclf]: https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV.html
[khalib-docs]: https://khiopslab.github.io/khalib

16 changes: 13 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# This script must be executed in its directory
import importlib
import sys

# Obtain the project's version
sys.path.append("../")
khalib_version = importlib.metadata.version("khalib")

# Basic Information
project = "khalib"
author = "Felipe Olmos"
release = "0.1"
release = khalib_version

# Sphinx extensions
extensions = [
"myst_nb", # activates myst_parser as well
"numpydoc",
Expand All @@ -11,13 +21,13 @@
"sphinx.ext.intersphinx",
]

# Basic Sphinx config
default_role = "obj"
templates_path = ["_templates"]
exclude_patterns = []

html_theme = "furo"
html_static_path = ["_static"]
html_title = f"<h6><center>{project} {release}</center></h6>"
default_role = "obj"

# Extensions configs

Expand Down
10 changes: 4 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
## How does it work

`khalib` proposes histogram-based calibration and its error estimation. Its differentiating factor
is that uses [Khiops][khiops-org] to construct the histogram in which {math}`P(Y = 1 | S)` is
estimated. These histograms have the following properties:
is that uses Khiops to construct the histogram in which {math}`P(Y = 1 | S)` is estimated. These
histograms have the following properties:
- They balance class purity, model complexity and data fitness.
- They are non-parametric: The optimal histogram is searched without constraint in number of bins or
bin width. This implies that the user doesn't need to set a number of bins nor their widths.


[khiops-org]: https://khiops.org
[khiops11-setup]: https://khiops.org/11.0.0-b.0/setup/
[sk-calclf]: https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV.html
[khalib-docs]: https://khiopsml.github.io/khalib
<!--[khiops-org]: https://khiops.org-->


See the [Quickstart](quickstart) and [API reference](api) to learn how to use the library.
Expand All @@ -40,5 +37,6 @@ API Reference <api>
:hidden:

Khiops <https://www.khiops.org>
Github <https://github.com/KhiopsLab/khalib>
```

16 changes: 16 additions & 0 deletions docs/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@
"print(\"Reduction :\", (ece_test - calib_ece_test) / ece_test)\n",
"_ = khalib.build_reliability_diagram(calib_hist_y_test_scores, y_test)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0370a02f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "edf18fbe",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
4 changes: 4 additions & 0 deletions docs/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@
print("CALIB HIST ECE:", calib_hist_ece_test)
print("Reduction :", (ece_test - calib_ece_test) / ece_test)
_ = khalib.build_reliability_diagram(calib_hist_y_test_scores, y_test)

# %%

# %%
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
alias pc := pre-commit
pre-commit:
uv run pre-commit run --all-files
uvx pre-commit run --all-files

alias d := docs
docs:
Expand Down
Loading