Getting Started#

The most straightforward way to use Ex-Fuzzy is to fit a fuzzy rule-based classifier or regressor to a dataset, then inspect the learned rules and predictions. A couple of examples of this can be found in the “demos” folder.

A brief piece of code that does this case of use is the following:

import ex_fuzzy.fuzzy_sets as fs
import ex_fuzzy.evolutionary_fit as GA
import ex_fuzzy.utils as  utils
import ex_fuzzy.eval_tools as eval_tools

iris = datasets.load_iris()
X = pd.DataFrame(iris.data, columns=iris.feature_names)
y = iris.target


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=0)
fl_classifier = GA.BaseFuzzyRulesClassifier(nRules=10, nAnts=4)
fl_classifier.fit(X_train, y_train, n_gen=50, pop_size=30)

fuzzy_evaluator = eval_tools.FuzzyEvaluator(fl_classifier)
fuzzy_evaluator.eval_fuzzy_model(X_train, y_train, X_test, y_test,
                    plot_rules=True, print_rules=True, plot_partitions=True)

This code trains the classifier and also plots the rules, prints them on screen and show the linguistic variables optimized in the process.

For continuous targets, use ex_fuzzy.BaseFuzzyRulesRegressor. It supports crisp Takagi-Sugeno and fuzzy Mamdani consequents, with either the default PyMoo backend or GPU-oriented backend="evox" optimization. See Fuzzy Regression for a complete example.

In the following, we will explain how the different processes to perform fuzzy inference are automated in this code, and how they can be perfomed manually.

The next step is Creating fuzzy sets and fuzzy variables.