Ex-Fuzzy Documentation#
Ex-Fuzzy is a Python library for explainable fuzzy logic inference and approximate reasoning. It provides tools for building, training, and analyzing fuzzy rule-based classifiers and regressors with a focus on readable rules and reproducible experiments.
Get up and running with Ex-Fuzzy in minutes. Learn the basics of fuzzy classification and regression through practical examples.
Comprehensive tutorials and examples for building fuzzy classifiers and regressors, analyzing patterns, and visualizing results.
Complete reference for all classes, functions, and modules with detailed descriptions and examples.
Real-world examples and case studies demonstrating Ex-Fuzzy’s capabilities across different domains.
Key Features#
Generate interpretable fuzzy rules that provide transparent decision-making processes for your machine learning models.
GPU-accelerated evolutionary optimization with the EvoX backend for classifiers and Type-1 regressors, with automatic population and sample batching.
Built-in plotting capabilities for fuzzy sets, rules, pattern stability analysis, and model performance metrics.
Train FERL rule trees with native belief, plausibility, ignorance, and set-valued predictions in a single deterministic pass.
Modular design allows easy customization of fuzzy sets, membership functions, and inference mechanisms.
Advanced tools for analyzing pattern stability, variable importance, and rule discovery consistency across multiple runs.
Designed for academic research with comprehensive statistical testing, bootstrapping, and experimental validation tools.
Quick Example#
Here’s a simple example to get you started:
from ex_fuzzy import BaseFuzzyRulesClassifier, eval_tools
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import pandas as pd
# Load and prepare data
iris = load_iris()
X = pd.DataFrame(iris.data, columns=iris.feature_names)
y = iris.target
# Split the data
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=0
)
# Create and train fuzzy classifier
classifier = BaseFuzzyRulesClassifier(nRules=10, nAnts=4)
classifier.fit(X_train, y_train, n_gen=50, pop_size=30)
# Early stopping defaults: patience=10, min_delta=1e-4
# Evaluate and visualize
evaluator = eval_tools.FuzzyEvaluator(classifier)
evaluator.eval_fuzzy_model(
X_train, y_train, X_test, y_test,
plot_rules=True, print_rules=True, plot_partitions=True
)
Regression Example#
Regression follows the same estimator workflow and optimizes training-set \(R^2\):
from ex_fuzzy import BaseFuzzyRulesRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
X, y = make_regression(n_samples=500, n_features=5, noise=5.0, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=0
)
regressor = BaseFuzzyRulesRegressor(
nRules=20,
nAnts=3,
consequent_type="crisp", # or "fuzzy" for Mamdani output sets
backend="pymoo", # or "evox" for batched PyTorch optimization
)
regressor.fit(X_train, y_train, n_gen=50, pop_size=50)
predictions = regressor.predict(X_test)
print(regressor.score(X_test, y_test))
regressor.print_rules()
Installation#
Install Ex-Fuzzy using pip:
pip install ex-fuzzy
Or install from source:
git clone https://github.com/fuminides/ex-fuzzy.git
cd ex-fuzzy
pip install -e .
Choosing a Workflow#
Goal |
Start with |
|---|---|
Train a standard interpretable classifier |
|
Train an interpretable Type-1 fuzzy regressor |
|
Mine candidate rules before optimization |
|
Return prediction sets with coverage guarantees |
|
Learn a greedy rule tree with native evidential uncertainty |
|
Grow a deeper, more accurate evidential rule tree |
|
Mine and select a compact fuzzy association rule base |
|
Use GPU-accelerated evolutionary optimization |
|
Save and reload fuzzy variables |
|
Documentation Contents#
Getting Started
User Guide
Examples
API Reference
Development
Topic Reference
- Getting Started
- Creating fuzzy sets and fuzzy variables
- Using Fuzzy Rules
- Optimizing a Fuzzy rule base for a classification problem
- Visualize rules and results
- Computing fuzzy partitions
- Genetic algorithm details
- General Type 2
- Temporal Fuzzy Sets
- Extending Ex-Fuzzy
- Persistence
- Advanced classifiers
- Bootstrapping and rule robustness
Community and Support#
Join our community discussions, ask questions, and share your projects.
Found a bug or have a feature request? Let us know on GitHub.
Help improve Ex-Fuzzy by contributing code, documentation, or examples.
Get in touch with the development team for collaboration or support.
Citation#
If you use Ex-Fuzzy in your research, please cite:
@article{fumanal2024ex,
title={Ex-Fuzzy: A Library for Symbolic Explainable Ai Through Fuzzy Logic Programming},
author={Fumanal Idocin, Javier and Andreu-Perez, Javier},
journal={Neurocomputing},
year={2024},
publisher={Elsevier}
}