Rules formation method using fuzzy c means clustering method.
44 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mamta
el 27 de Dic. de 2023
Comentada: Sam Chak
el 17 de En. de 2026 a las 4:53
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 .
0 comentarios
Respuesta aceptada
Sam Chak
el 27 de Dic. de 2023
Hi @Mamta
Here is a simple example of automatically generating fuzzy rules from data using the FCM clustering method. The data is randomly generated. For more information, you can look up the 'genfis()' command. Please note that this method requires the Fuzzy Logic Toolbox.
Let me know if the proposed approach in the Answer is helpful.
%% 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 = 'auto'; % set auto or specify a fixed number of FCM clusters
opt.Verbose = 0;
fis = genfis(inputData, outputData, opt); % generate FIS from the data
showrule(fis)
%% Plot data
figure
scatter3(inputData(:,1), inputData(:,2), outputData), grid on
xlabel("Input 1"), ylabel("Input 2"), zlabel("Output")
%% Plot membership functions
figure
[in1, mf1] = plotmf(fis, 'input', 1);
subplot(3,1,1), plot(in1, mf1), grid on
xlabel('Membership Functions for Input 1'), ylabel('\mu')
[in2, mf2] = plotmf(fis, 'input', 2);
subplot(3,1,2), plot(in2, mf2), grid on
xlabel('Membership Functions for Input 2'), ylabel('\mu')
[out, mf3] = plotmf(fis, 'output', 1);
subplot(3,1,3), plot(out, mf3), grid on
xlabel('Membership Functions for Output'), ylabel('\mu')
6 comentarios
Más respuestas (3)
Sam Chak
el 29 de Dic. de 2023
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 comentario
Sam Chak
el 29 de Dic. de 2023
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')
0 comentarios
Sam Chak
el 30 de Dic. de 2023
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 comentarios
jahan jahan
el 14 de En. de 2026 a las 10:46
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
el 17 de En. de 2026 a las 4:53
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.
Ver también
Categorías
Más información sobre Fuzzy Logic in Simulink en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






