Following the tip example from scikit-fuzzy, I have used the following code to create an input/output to a fuzzy control system:
quality = ctrl.Antecedent(np.arange(0, 11, 1), 'quality')
service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')
tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')
quality.automf(3)
service.automf(3)
tip.automf(3)
In the "Fuzzy rules" section of the example, the rules are manually written. I would like to generate them from training examples.
Suppose I have a set of (quality, service, tip) tuples, where quality and service range from 0 to 10 and tip ranges from 0 to 25. I would like to be able to generate automatically a rule from each training tuple. In order to do so, I need to map the values of quality and service (respectively tip) to a term (a.k.a linguistic value): either 'poor', 'average', or 'good' (respectively 'low', 'medium', or 'high').
How can I do that with scikit-fuzzy ?
The function I need is skfuzzy.interp_membership: if I want to have the fuzzy term/linguistic value for the crisp value 4.0, I evaluate each membership function at 4.0:
skfuzzy.interp_membership(np.arange(0, 11, 1), quality['poor'].mf, 4.0)
skfuzzy.interp_membership(np.arange(0, 11, 1), quality['average'].mf, 4.0)
skfuzzy.interp_membership(np.arange(0, 11, 1), quality['good'].mf, 4.0)
and then the fuzzy value would be the one for which the membership function has the maximum value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With