FuzzyCocoPython documentation
FuzzyCocoPython
Python bindings and scikit-learn style estimators for fuzzycoco,
an evolutionary fuzzy rule learning engine written in C++. This package wraps the C++ core as a Python module
and exposes FuzzyCocoClassifier and FuzzyCocoRegressor with a familiar fit/predict API.
Features
Train fuzzy rule-based classifiers and regressors using
fit,predict, andscoreInspect learned linguistic variables, rules, and activation statistics from Python
Persist trained estimators with
save/loadhelpers based onjoblib
Installation
This package is not yet on PyPI; install it from source. Make sure the following prerequisites are available:
A C++17 compiler toolchain (GCC/Clang on Linux & macOS, MSVC on Windows)
uv is recommended for dependency management, but
pipworks just as well
Clone the repository, initialise the fuzzycoco submodule, then build and install in editable mode with uv:
git clone https://github.com/Lonza-RND-Data-Science/fuzzycocopython.git
cd fuzzycocopython
git submodule update --init --recursive
uv venv
source .venv/bin/activate
uv pip install -e .
If you prefer the standard tooling, create a virtual environment manually and install with pip:
python -m venv .venv
source .venv/bin/activate
pip install -e .
When you only need the published bindings and not the repository, install straight from GitHub:
pip install git+https://github.com/Lonza-RND-Data-Science/fuzzycocopython.git
For development tasks (tests, linting, docs) install the optional toolchain:
uv pip install -e '.[dev]'
The build compiles the bundled C++ bindings. Refer to the
fuzzycoco project for background on the engine itself.
Quick start
import pandas as pd
from sklearn.datasets import load_iris
from fuzzycocopython import FuzzyCocoClassifier
data = load_iris(as_frame=True)
clf = FuzzyCocoClassifier(random_state=0)
clf.fit(data.data, data.target)
preds = clf.predict(data.data)
score = clf.score(data.data, data.target)
print(f"Accuracy: {score:.3f}")
print(clf.rules_df_.head())
The estimators now expose scikit-learn style hyper-parameters for direct tuning:
from fuzzycocopython import FuzzyCocoClassifier
model = FuzzyCocoClassifier(nb_rules=10, nb_sets_in=3, random_state=42)
model.fit(X, y)
preds = model.predict(X)
Bit widths for variable and set indices are automatically derived from the training data. Override them with nb_bits_vars_in, nb_bits_sets_in, nb_bits_vars_out, or nb_bits_sets_out when you need full manual control.
For a guided tour, open demo.ipynb. Additional usage examples live in tests/test_fuzzycocopython.py.
Documentation
Full API documentation is available at Lonza-RND-Data-Science.github.io/fuzzycocopython. To build the docs locally run:
uv pip install -e '.[docs]'
uv run sphinx-build -W -b html docs docs/_build/html
Pre-commit hooks
Install and activate the provided hooks (Ruff lint/format, mypy, general hygiene) once per clone:
uv run pre-commit install
Run them against the full tree when needed:
uv run pre-commit run --all-files
License
This fuzzycoco software is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).
Contents
Guide
API Reference