Skip to content

Repository files navigation

XCSF learning classifier system

Latest Version PyPI package Linux Build MacOS Build Windows Build DOI

XCSF is an accuracy-based learning classifier system for online supervised and reinforcement learning. Rather than fitting a single global model, it uses an evolutionary algorithm to design a population of rules, each of which matches a region of the input space and predicts with its own simple model (for example, a linear regression or a small neural network).

This repository provides a C implementation that can be built as a stand-alone binary or used as a Python library with a scikit-learn-style interface. See the project wiki for features, build instructions, and usage.

Quick start

Installation

pip install xcsf

Minimal example

Fit y = sin(2πx) using local linear models:

import numpy as np
import xcsf


def f(x):
    return np.sin(2 * np.pi * x)


rng = np.random.default_rng(1)
X_train = rng.random((1000, 1))
X_test = np.linspace(0, 1, 200).reshape(-1, 1)

xcs = xcsf.XCS(
    x_dim=1,
    y_dim=1,
    n_actions=1,
    pop_size=500,
    max_trials=20000,
    random_state=1,
    loss_func="mse",
    e0=0.0001,
    alpha=1,
    prediction={"type": "rls_linear"},
)

xcs.fit(X_train, f(X_train), verbose=False)
print(f"Test MSE: {xcs.score(X_test, f(X_test)):.1e}")  # ~3.1e-05

For more Python examples, see the python folder, which contains scripts and the equivalent notebooks.

Contributing

Contributions to this repository are very welcome.

See our contributing guide for details.