{"id":9298,"library":"scikit-fuzzy","title":"scikit-fuzzy","description":"scikit-fuzzy is a fuzzy logic toolkit for SciPy, providing a robust collection of independently developed and implemented fuzzy logic algorithms. It aims to offer a Pythonic alternative to closed-source fuzzy logic software. The library is currently at version 0.5.0 and receives periodic updates, indicating active maintenance and development.","status":"active","version":"0.5.0","language":"en","source_language":"en","source_url":"https://github.com/scikit-fuzzy/scikit-fuzzy","tags":["fuzzy logic","scipy","numpy","control systems","AI","machine learning","data science"],"install":[{"cmd":"pip install -U scikit-fuzzy","lang":"bash","label":"PyPI (recommended)"},{"cmd":"conda install -c conda-forge scikit-fuzzy","lang":"bash","label":"Anaconda/Conda-forge"}],"dependencies":[{"reason":"Required for plotting and visualization of fuzzy sets and control system results.","package":"Matplotlib","optional":false},{"reason":"Fundamental for numerical operations and array manipulation, which underpins all fuzzy set representations.","package":"NumPy","optional":false},{"reason":"Provides core scientific computing functions that scikit-fuzzy builds upon.","package":"SciPy","optional":false},{"reason":"Used internally for certain graph-based operations, especially within fuzzy control systems.","package":"NetworkX","optional":false}],"imports":[{"note":"The common and recommended practice is to import `skfuzzy` with the alias `fuzz` for brevity and consistency with examples.","wrong":"import skfuzzy","symbol":"skfuzzy","correct":"import skfuzzy as fuzz"},{"note":"Classes for building fuzzy control systems (e.g., `Antecedent`, `Consequent`, `ControlSystem`) reside in the `control` submodule and are typically aliased as `ctrl`.","wrong":"import skfuzzy.control","symbol":"control","correct":"from skfuzzy import control as ctrl"},{"note":"Often used alongside scikit-fuzzy for defining universe variables and membership functions.","symbol":"numpy","correct":"import numpy as np"},{"note":"Frequently used for visualizing fuzzy sets, membership functions, and control surfaces.","symbol":"pyplot","correct":"from matplotlib import pyplot as plt"}],"quickstart":{"code":"import numpy as np\nimport skfuzzy as fuzz\nimport matplotlib.pyplot as plt\n\n# Generate universe variables\nx = np.arange(0, 11, 1) # Points from 0 to 10\n\n# Generate fuzzy membership functions\nlow = fuzz.trimf(x, [0, 0, 5])\nmedium = fuzz.trimf(x, [0, 5, 10])\nhigh = fuzz.trimf(x, [5, 10, 10])\n\n# Visualize these universes and membership functions\nplt.figure()\nplt.plot(x, low, 'b', linewidth=1.5, label='Low')\nplt.plot(x, medium, 'g', linewidth=1.5, label='Medium')\nplt.plot(x, high, 'r', linewidth=1.5, label='High')\nplt.title('Fuzzy Membership Functions')\nplt.ylabel('Membership value')\nplt.xlabel('Universe Variable')\nplt.legend()\nplt.grid(True)\nplt.show()","lang":"python","description":"This quickstart demonstrates how to define a universe of discourse using NumPy and then create triangular fuzzy membership functions using `fuzz.trimf`. It then plots these membership functions using Matplotlib to visualize the fuzzy sets. This is a fundamental step in building any fuzzy logic system with scikit-fuzzy."},"warnings":[{"fix":"Be aware of the IEEE rounding standard when comparing results with MATLAB. This is intentional and not considered a bug.","message":"scikit-fuzzy adheres to the IEEE standard for rounding, which can lead to slight numerical differences compared to MATLAB's rounding behavior (e.g., 2.5 rounds to 2, 3.5 rounds to 4). If re-implementing algorithms from MATLAB, expect minor inconsistencies due to this.","severity":"breaking","affected_versions":"All versions"},{"fix":"Consult the `skfuzzy.control` documentation and examples for the current API. Update control system definitions to use `ctrl.Antecedent`, `ctrl.Consequent`, etc., and leverage `ControlSystemSimulation` for computations.","message":"The fuzzy control system API (within `skfuzzy.control`) underwent significant changes and improvements in earlier major releases (e.g., 0.3.0 introduced a new API). Older implementations of fuzzy control systems might require updates to use the new `Antecedent`, `Consequent`, `ControlSystem`, and `ControlSystemSimulation` classes.","severity":"breaking","affected_versions":"< 0.3.0"},{"fix":"Always use `from skfuzzy import control as ctrl` to access fuzzy control system components, then reference them as `ctrl.Antecedent`, `ctrl.Consequent`, etc.","message":"Classes and functions related to fuzzy control systems (e.g., `Antecedent`, `Consequent`, `ControlSystem`) are *not* directly available in the main `skfuzzy` namespace. They must be explicitly imported from the `skfuzzy.control` submodule.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If encountering issues with Python 3.12, consider using Python 3.11 or earlier. Monitor `scikit-fuzzy`'s GitHub for updates on Python 3.12 compatibility. Ensure all dependencies are up-to-date and compatible with your Python version.","message":"There have been reports of compatibility issues with Python 3.12, often surfacing through underlying dependency conflicts. While `scikit-fuzzy` aims for broad Python support, specific environment configurations with Python 3.12 might encounter problems.","severity":"gotcha","affected_versions":"0.5.0 (with Python 3.12)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change your import statement to `from skfuzzy import control as ctrl` and then use `ctrl.Antecedent(...)`.","cause":"The `Antecedent` class, along with other control system components, is located in the `skfuzzy.control` submodule, not directly in the `skfuzzy` top-level package.","error":"AttributeError: 'module' object has no attribute 'Antecedent'"},{"fix":"Double-check that the string names passed to `ctrl.Antecedent('name', ...)` and `ctrl.Consequent('name', ...)` exactly match the keys used when setting input values to a `ControlSystemSimulation` instance (e.g., `sim.input['name'] = value`). Also verify the type and range of the input provided to `Antecedent` or `Consequent` constructor matches expected `np.arange` or similar.","cause":"This error typically occurs when initializing `Antecedent` or `Consequent` objects within `skfuzzy.control`. It signifies a mismatch in the variable name provided as input to `ControlSystemSimulation.input` or incorrect definition of the control system variables.","error":"ValueError: Unexpected input: <variable_name>"},{"fix":"Review the definitions of your universe variables (`np.arange`), membership functions (`fuzz.trimf`, `fuzz.gaussmf`, etc.), and fuzzy rules. Ensure that membership functions cover the expected range of inputs and that rules are logically consistent. Pay close attention to the input values provided to the `compute()` method of a `ControlSystemSimulation`.","cause":"While some related reports mention `fuzzywuzzy`, similar assertion errors in `scikit-fuzzy` often arise from incorrect definition of universe variables, membership functions, or fuzzy rules, leading to invalid input during computation or inference. This can include non-overlapping membership functions or improper ranges.","error":"AssertionError: fuzzy system python assertion error during input"}]}