Metadata-Version: 2.5
Name: pylfit
Version: 1.0.0a1
Summary: Learn interpretable logic rules from data (LFIT-family algorithms).
Project-URL: Homepage, https://github.com/Tony-sama/pylfit
Project-URL: Repository, https://github.com/Tony-sama/pylfit
Project-URL: Issues, https://github.com/Tony-sama/pylfit/issues
Project-URL: Documentation, https://tony-sama.github.io/pylfit/
Project-URL: Changelog, https://tony-sama.github.io/pylfit/changelog.html
Author-email: Tony Ribeiro <tonyribeiro.contact@gmail.com>
License-Expression: GPL-3.0-only
License-File: AUTHORS.md
License-File: LICENSE
Keywords: Boolean networks,LFIT,inductive logic programming,interpretable machine learning,learning from interpretation transition,rule learning,symbolic AI
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: numpy>=2.2
Requires-Dist: pandas>=2.3
Provides-Extra: dev
Requires-Dist: codespell; extra == 'dev'
Requires-Dist: interrogate; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pandas-stubs; extra == 'dev'
Requires-Dist: pydoclint; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: pytest>=9; extra == 'dev'
Requires-Dist: ruff<0.18,>=0.17; extra == 'dev'
Provides-Extra: docs
Requires-Dist: myst-parser; extra == 'docs'
Requires-Dist: pydata-sphinx-theme; extra == 'docs'
Requires-Dist: sphinx; extra == 'docs'
Requires-Dist: sphinx-gallery; extra == 'docs'
Description-Content-Type: text/markdown

# pylfit

<!-- Badges, once the repository is public and hosted: tests (CI),
docs, PyPI version, license, and the release DOI. -->

<!-- start-intro -->

pylfit learns logic rules from data. Give it a table of examples, and it
returns rules such as `y(1) :- a(0), c(1).` ("`y` can be 1 when `a` is
0 and `c` is 1") that you can read, check and use to predict.

pylfit is for people who need a model they can inspect: every
prediction traces back to the rules that made it. Its main algorithm,
`GULA`, learns the most general rules the data doesn't contradict, all
of them, with guarantees: no rule contradicts an example, every
combination of feature values is matched by some rule, and no rule
keeps a condition it can do without. pylfit implements algorithms of
the Learning From Interpretation Transitions (LFIT) framework, whose
original application is learning Boolean networks, models where each
variable is on or off and its next value depends on the others', such
as gene regulatory networks, from observed state transitions. It works
on any table of categorical data.

> pylfit 1.0 is a ground-up rewrite, released as alpha pre-releases on
> PyPI; its API may still change before 1.0.0. It is incompatible with
> pylfit 0.x; see [Migrate from pylfit 0.x][migration].

[migration]: https://tony-sama.github.io/pylfit/how-to/migration.html

## Installation

pylfit needs Python 3.11 or later, pandas 2.3 or later and NumPy 2.2 or
later, which `pip` installs for you. 1.0 is a pre-release, so name it:

```bash
pip install --upgrade "pylfit>=1.0.0a1"
```

Plain `pip install pylfit` still installs 0.5.1, the last 0.x release.
The development version is on the repository's `next` branch:

```bash
pip install "git+https://github.com/Tony-sama/pylfit.git@next"
```

To keep using pylfit 0.x, pin it: `pip install "pylfit<1" numpy pandas`
(0.5.1 uses both without declaring them).

## Quickstart

A `Dataset` stores every value as a string, so the rules and the
model's predictions read `"0"`, not `0`.

```pycon
>>> import pandas as pd
>>> from pylfit import GULA, Dataset, WeightedRuleSetModel
>>> df = pd.DataFrame(
...     [
...         [0, 0, 0, 0],
...         [0, 0, 1, 1],
...         [0, 1, 0, 1],
...         [0, 1, 1, 1],
...         [1, 0, 0, 0],
...         [1, 0, 1, 0],
...         [1, 1, 0, 1],
...         [1, 1, 1, 1],
...     ],
...     columns=["a", "b", "c", "y"],
... )
>>> dataset = Dataset(df, features=["a", "b", "c"], targets=["y"])
>>> rules = GULA.fit(dataset)
>>> for rule in rules:
...     print(rule)
y(0) :- a(1), b(0).
y(0) :- b(0), c(0).
y(1) :- a(0), c(1).
y(1) :- b(1).
>>> model = WeightedRuleSetModel(dataset, rules)
>>> model.predict(pd.DataFrame([{"a": "0", "b": "1", "c": "0"}]))
[{'y': '1'}]

```

<!-- end-intro -->

## Where to start

- To use pylfit: [Getting started][getting-started], then
  [Prepare your data][prepare-data].
- To understand how it works: [About LFIT rules][about-rules] and
  [About the algorithms][about-algorithms].
- To contribute: [CONTRIBUTING.md][contributing].

The `examples/` directory has runnable scripts: `starter.py` is a whole
experiment to copy, `tutorial_heart_disease.py` goes from clinical
measurements to rules that explain each prediction, `dynamics.py`
learns a dynamical system, and the `benchmark_*.py` scripts compare the
algorithms and their options.

## Citing

See [Citing pylfit][citing] and `CITATION.cff`.

## Acknowledgements

pylfit is written and maintained by Tony Ribeiro (`AUTHORS.md`). It
implements the Learning From Interpretation Transitions (LFIT)
framework, developed with many colleagues over more than ten years;
they are credited on the [Credits][credits] page. pylfit 1.0 was
written with AI assistants; the same page says [which, and how][ai].

## License

GPL-3.0-only; see `LICENSE`. The Boolean-network files under
`tests/data/bnet/` come from PyBoolNet and keep its LGPL license, and
the UCI datasets under `examples/data/` are CC BY 4.0; see the README in
each directory.

See also `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md` and `AUTHORS.md`.

<!-- Absolute links, so that they work on PyPI too. -->

[getting-started]: https://tony-sama.github.io/pylfit/getting-started.html
[prepare-data]: https://tony-sama.github.io/pylfit/how-to/prepare-data.html
[about-rules]: https://tony-sama.github.io/pylfit/explanation/about-rules.html
[about-algorithms]: https://tony-sama.github.io/pylfit/explanation/about-algorithms.html
[contributing]: https://github.com/Tony-sama/pylfit/blob/next/CONTRIBUTING.md
[citing]: https://tony-sama.github.io/pylfit/citing.html
[credits]: https://tony-sama.github.io/pylfit/credits.html
[ai]: https://tony-sama.github.io/pylfit/credits.html#how-pylfit-1-0-was-written
