Rules formation method using fuzzy c means clustering method.
Show older comments
I want to know about tool that automatically genreate the rules on the basis of dataset with fuzzy c means clustering method .Please explain with any dataset to generate rules automatically .It is very urgent for my study .
Accepted Answer
More Answers (3)
Hi @Mamta
Your observation is correct. When employing the data clustering method, the fuzzy system (FIS) will have one fuzzy rule for each cluster, and each input and output variable will have one membership function per cluster. In the following example, I have set a fixed number of clusters.
%% Data with 2 inputs and 1 output
inputData = [2*rand(100,1) 3*rand(100,1)-1.5]; % input data
outputData = 5*rand(100,1); % output data
%% Generate fuzzy rules from data using FCM clustering
opt = genfisOptions('FCMClustering', 'FISType', 'mamdani'); % set method & FIS type
opt.NumClusters = 3; % set a fixed number of FCM clusters
opt.Verbose = 0;
myFIS = genfis(inputData, outputData, opt); % generate FIS from the data
showrule(myFIS)
%% Plot membership functions
figure
[in1, mf1] = plotmf(myFIS, 'input', 1);
subplot(3,1,1), plot(in1, mf1), grid on
xlabel('Membership Functions for Input 1'), ylabel('\mu')
[in2, mf2] = plotmf(myFIS, 'input', 2);
subplot(3,1,2), plot(in2, mf2), grid on
xlabel('Membership Functions for Input 2'), ylabel('\mu')
[out, mf3] = plotmf(myFIS, 'output', 1);
subplot(3,1,3), plot(out, mf3), grid on
xlabel('Membership Functions for Output'), ylabel('\mu')
1 Comment
Here is the 3rd answer at your request. If you want to generate rules with antecedents that contain all possible combinations of the input membership function, then you must use the Grid Partition method. However, this "non-clustering" method will produce only the Sugeno FIS, which, in my opinion, is more powerful than the classic Mamdani FIS.
Don't forget to vote for other answers as tokens of appreciation for providing explanations and guidance.
%% Data with 2 inputs and 1 output
inputData = [2*rand(100,1) 3*rand(100,1)-1.5]; % input data
outputData = 5*rand(100,1); % output data
%% Generate fuzzy rules from data using FCM clustering
opt = genfisOptions('GridPartition'); % will create Sugeno FIS
opt.NumMembershipFunctions = [3 3]; % specify number of MFs for each input
opt.InputMembershipFunctionType = "gaussmf";
myFIS = genfis(inputData, outputData, opt); % generate Sugeno FIS from the data
showrule(myFIS)
%% Plot membership functions
figure
[in1, mf1] = plotmf(myFIS, 'input', 1);
subplot(2,1,1), plot(in1, mf1), grid on
xlabel('Membership Functions for Input 1'), ylabel('\mu')
[in2, mf2] = plotmf(myFIS, 'input', 2);
subplot(2,1,2), plot(in2, mf2), grid on
xlabel('Membership Functions for Input 2'), ylabel('\mu')
Hi @Mamta
Here is an example to demonstrate how to change the names of the membership functions to 'low,' 'med,' and 'high' for Input 1. Don't forget to vote on the Answer.
%% Data with 2 inputs and 1 output
inputData = [2*rand(50,1) 3*rand(50,1)-1.5]; % input data
outputData = 5*rand(50,1); % output data
%% Generate fuzzy rules from data using FCM clustering
opt = genfisOptions('FCMClustering', 'FISType', 'mamdani'); % set method & FIS type
opt.NumClusters = 3; % set auto or specify a fixed number of FCM clusters
opt.Verbose = 0;
myFIS = genfis(inputData, outputData, opt) % generate FIS from the data
%% genfis auto-assigned the names of the fuzzy sets as in1cluster1, in1cluster2, in1cluster3
plotmf(myFIS, 'input', 1)
%% Check the names of the fuzzy sets of Input 2
myFIS.Inputs(2).MembershipFunctions
%% The names of the fuzzy sets can be renamed using this syntax
myFIS.Inputs(1).MembershipFunctions(1).Name = "low";
myFIS.Inputs(1).MembershipFunctions(2).Name = "med";
myFIS.Inputs(1).MembershipFunctions(3).Name = "high";
plotmf(myFIS, 'input', 1)
5 Comments
Mamta
on 6 Jan 2024
Sam Chak
on 15 Jan 2024
Hi @Mamta
The benefit is that FCM allows for flexibility in the number of clusters to be formed, and therefore, rules can be generated for an arbitrary number of clusters. Regarding why it generated 4 rules, it is because the membership values obtained from FCM can be interpreted as the strength of association of a data point with different clusters. Something like "If the input is similar to cluster A, then the output is associated with class A."
The real question is, "Did the FCM produce a fairly accurate fuzzy system with only 4 rules to predict the input-output pair?" If it didn't, the data may exhibit a complex pattern that can be better captured by a varying number of clusters. Therefore, multiple runs with different initializations may be necessary.
If you want to manually enter all possible rules for 9 inputs of three membership functions for each input, then you will have to decide on the outputs of
number of rules. How accurate it will be? That's another story.
number of rules. How accurate it will be? That's another story.
jahan jahan
on 14 Jan 2026
Hi,
how can I make a forecast from an FIS-trained model?
it mean there is a MATLAB command used for prediction from a fuzzy model in MATLAB version 2018?
Thank you in advance
JJ
Sam Chak
on 17 Jan 2026
Hi @jahan jahan
The "Deep Learning Toolbox," "Statistics and Machine Learning Toolbox," and "System Identification Toolbox" all include the predict() command to compute model outputs. In the "Fuzzy Logic Toolbox," the evalfis() command is used to evaluate the .fis file for the input values and return the corresponding output values. This command is capable of more than just returning outputs; it can also provide intermediate results from the fuzzy decision-making process.
However, in the context of data science, the concept of "prediction" strongly implies a comparison between the predicted output and the actual data, particularly during the model development and validation phases. Simply obtaining the model outputs does not effectively indicate the accuracy of the predictions.
If you have an initial FIS and a trained FIS, you can use the comparefis() command to evaluate each FIS and display the simulated output values in a stacked plot. If you wish to compare the fuzzy model output with reference actual output data, you may use the plotfiserr() command. You can also calculate the mean squared error (MSE) between the predicted output vector X and the actual output data vector Y. If you have the "Image Processing Toolbox" installed, you can use the immse(X, Y) command directly.
Categories
Find more on Fuzzy Inference System Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




