A Python package for fuzzy model estimation
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install pyfumepyFUME
pyFUME is a Python package for automatic Fuzzy Models Estimation from data [1]. pyFUME contains functions to estimate the antecedent sets and the consequent parameters of a Takagi-Sugeno fuzzy model directly from data. This information is then used to create an executable fuzzy model using the Simpful library. pyFUME also provides facilities for the evaluation of performance. For more information about pyFUME's functionalities, please check the online documentation.
Usage
For the following example, we use the Concrete Compressive Strength data set [2] as can be found in the UCI repository. The code in Example 1 is simple and easy to use, making it ideal to use for practitioners who wish to use the default settings or only wish to use few non-default settings using additional input arguments (Example 2). Users that wish to deviate from the default settings can use the code as shown in Example 3. The code of the Simpful model that is generated is automatically saved (in the same location as the pyFUME script is ran from) under the name 'Simpful_code.py'
Note
Please be aware that pyFUME's feature selection functionality makes use of multiprocessing. When feature selection is used, the main script should always be guarded by including "if __name__ == '__main__':" in the header the script. When the Spyder IDE is used, one should include "if __name__ == '__main__' and '__file__' in globals():".
Example 1
from pyfume import pyFUME
# Set the path to the data and choose the number of clusters
path='./Concrete_data.csv'
nc=3
# Generate the Takagi-Sugeno FIS
FIS = pyFUME(datapath=path, nr_clus=nc)
# Calculate and print the accuracy of the generated model
MAE=FIS.calculate_error(method="MAE")
print ("The estimated error of the developed model is:", MAE)
## Use the FIS to predict the compressive strength of a new concrete sample
# Extract the model from the FIS object
model=FIS.get_model()
# Set the values for each variable
model.set_variable('Cement', 300.0)
model.set_variable('BlastFurnaceSlag', 50.0)
model.set_variable('FlyAsh', 0.0)
model.set_variable('Water', 175.0)
model.set_variable('Superplasticizer',0.7)
model.set_variable('CoarseAggregate', 900.0)
model.set_variable('FineAggregate', 600.0)
model.set_variable('Age', 45.0)
# Perform inference and print predicted value
print(model.Sugeno_inference(['OUTPUT']))
Example 2
from pyfume import pyFUME
# Set the path to the data and choose the number of clusters
path='./Concrete_data.csv'
nc=3
# Generate the Takagi-Sugeno FIS
FIS = pyFUME(datapath=path, nr_clus=nc, feature_selection='fst-pso')
# Calculate and print the accuracy of the generated model
MAE=FIS.calculate_error(method="MAE")
print ("The estimated error of the developed model is:", MAE)
## Use the FIS to predict the compressive strength of a new concrete sample
# Extract the model from the FIS object
model=FIS.get_model()
# Set the values for each variable
model.set_variable('Cement', 300.0)
model.set_variable('BlastFurnaceSlag', 50.0)
model.set_variable('FlyAsh', 0.0)
model.set_variable('Water', 175.0)
model.set_variable('Superplasticizer',0.7)
model.set_variable('CoarseAggregate', 900.0)
model.set_variable('FineAggregate', 600.0)
model.set_variable('Age', 45.0)
# Perform inference and print predicted value
print(model.Sugeno_inference(['OUTPUT']))