A Python implementation of Adaptive Neuro-Fuzzy Inference Systems (ANFIS), combining neural networks and fuzzy logic for interpretable machine learning. The implementation is based on the original ANFIS paper, adapting the model to perform both regression and classification tasks with customizable membership functions. A Recurrent ANFIS (RANFIS), a Gated Recurrent Unit ANFIS (GRU-ANFIS) and Long-Short Term memmory ANFIS (LSTM-ANFIS) are also implemented, suited for time series regression and classification. A Coactive ANFIS (CANFIS) is also included, for deeper neuro-fuzzy models.
- Regression and Classification
- Time Series Analysis with RANFIS, GRU-ANFIS and LSTM-ANFIS
- Deep Neuro-Fuzzy models with CANFIS
- Visualization and Interpretability via
.print_rules(),.plot_var(),.plot_rules(),.rule_activations() - Various Membership Functions (
GaussianMF,BellMF,TriangularMF,SigmoidMF) and T-Norms (MinAND,ProdAND,HamacherAND,FrankAND,LukasiewiczAND) - PyTorch Integration (GPU acceleration, optimizers, ...)
The repository is organized in the following directories:
- ANFISpy: has the implementation of the ANFIS's based models;
- examples: has jupyter-notebooks with examples of how to use the models;
- tests: has testing files for managing the code behaviour.
The installation of the package can be done using pip in a bash terminal:
pip install anfispyThen, the package can be imported in Python using:
from ANFISpy import ANFIS
from ANFISpy import RANFISThe ANFIS model can be used to perform both regression and classification, as explained in anfis_example.ipynb. To instantiate a regression model, set the value of n_classes in the output to 1.
from ANFISpy import ANFIS
n_vars = 3
mf_names = [['L', 'M', 'H']]
variables = {
'inputs': {
'n_sets': [3, 3, 3],
'uod': n_vars * [(0, 1)],
'var_names': ['var1', 'var2', 'var3'],
'mf_names': n_vars * mf_names,
},
'output': {
'var_names': 'out',
'n_classes': 1,
},
}
anfis_regression = ANFIS(variables, 'gaussian')To create a clasification model, set the value of n_classes in the output to a number of classes greater or equal to 2.
from ANFISpy import ANFIS
n_vars = 3
mf_names = [['L', 'M', 'H']]
variables = {
'inputs': {
'n_sets': [3, 3, 3],
'uod': n_vars * [(0, 1)],
'var_names': ['var1', 'var2', 'var3'],
'mf_names': n_vars * mf_names,
},
'output': {
'var_names': 'out',
'n_classes': 3,
},
}
anfis_classification = ANFIS(variables, 'bell')The notebook anfis_example.ipynb has a more detailed explanation of how to use the model, as well as the visualization methods implemented. The CANFIS, RANFIS, GRU-ANFIS and LSTM-ANFIS models are instantiated the same way as ANFIS, and examples can be seen in canfis_example.ipynb, ranfis_example.ipynb, gruanfis_example.ipynb and lstmanfis_example.ipynb.
If you used this package in your work, please cite the original paper ANFISpy: a python package for neuro-fuzzy models as:
@article{monteiro2026anfispy,
title={ANFISpy: a python package for neuro-fuzzy models},
author={Monteiro, Matheus Zaia and Wasques, Vinicius Francisco},
journal={Neural Computing and Applications},
volume={38},
number={4},
pages={59},
year={2026},
publisher={Springer}
}This repository was built by Matheus Zaia Monteiro under supervision of PhD Vinicius Francisco Wasques. Feel free to get in contact via the following e-mails: matheus.z.monteiro@gmail.com and/or vinicius.wasques@ilum.cnpem.br.