0% found this document useful (0 votes)
30 views8 pages

AI Lab 4T

The document outlines the implementation of a fuzzy logic system using the scikit-fuzzy library to determine tipping amounts based on service quality and quality of food. It defines antecedents for quality and service, and a consequent for tip, with various membership functions and rules for calculating tips. The system is demonstrated with example inputs and outputs, showcasing how the fuzzy logic approach can be applied to real-world scenarios.

Uploaded by

shakibtuhin8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views8 pages

AI Lab 4T

The document outlines the implementation of a fuzzy logic system using the scikit-fuzzy library to determine tipping amounts based on service quality and quality of food. It defines antecedents for quality and service, and a consequent for tip, with various membership functions and rules for calculating tips. The system is demonstrated with example inputs and outputs, showcasing how the fuzzy logic approach can be applied to real-world scenarios.

Uploaded by

shakibtuhin8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

!

pip install scikit-fuzzy

import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
#Auto membership function population is possible with .automf(3,5 or
7)
#[Link](3)
#[Link](3)
#quality = [Link]([Link](0,11,1),'quality')
#service = [Link]([Link](0,11,1),'service')
#tip = [Link]([Link](0,26,1),'tip')

quality = [Link]([Link](0,11,1),'quality')
service = [Link]([Link](0,11,1),'service')
tip = [Link]([Link](0,26,1), 'tip')

quality['poor'] = [Link]([Link],[0,0,5])
quality['acceptable'] = [Link]([Link],[0,5,10])
quality['amazing'] = [Link]([Link],[5,10,10])

service['bad'] = [Link]([Link],[0,0,5])
service['decent'] = [Link]([Link],[0,5,10])
service['great'] = [Link]([Link],[5,10,10])

#Custom membership functions can be built interactivity with a


familiar,
#Pythonic API
tip['low'] = [Link]([Link],[0,0,13])
tip['medium'] = [Link]([Link],[0,13,25])
tip['high'] = [Link]([Link],[13,13,25])

#You can see how this look with .view


quality['poor'].view()
service['great'].view()
tip['high'].view()

rule1 = [Link](quality['poor'] | service['bad'],tip['low'])


rule2 = [Link](service['decent'],tip['medium'])
rule3 = [Link](service['great'] | quality['amazing'],tip['high'])
#[Link]()
#[Link]()

tipping_ctrl = [Link]([rule1,rule2,rule3])
tipping = [Link](tipping_ctrl)

[Link]['quality'] = 6.5
[Link]['service'] = 9.8
#Crunch the number
[Link]()
print([Link]['tip'])
[Link](sim=tipping)

15.950841071496813
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
import [Link] as plt

# Define fuzzy variables


quality = [Link]([Link](0, 11, 1), 'quality')
service = [Link]([Link](0, 11, 1), 'service')
tip = [Link]([Link](0, 26, 1), 'tip')

# Membership functions
quality['very poor'] = [Link]([Link], [0, 0, 3])
quality['poor'] = [Link]([Link], [0, 3, 5])
quality['acceptable'] = [Link]([Link], [3, 5, 10])
quality['amazing'] = [Link]([Link], [5, 10, 10])
quality['very amazing'] = [Link]([Link], [10, 10, 10])

service['very bad'] = [Link]([Link], [0, 0, 3])


service['bad'] = [Link]([Link],[0,3,5])
service['decent'] = [Link]([Link],[3,5,10])
service['great'] = [Link]([Link],[5,10,10])
service['very great'] = [Link]([Link], [10, 10, 10])

tip['low'] = [Link]([Link], [0, 0, 13])


tip['medium'] = [Link]([Link], [0, 13, 25])
tip['high'] = [Link]([Link], [13, 25, 25])

#You can see how this look with .view


quality['acceptable'].view()
service['decent'].view()
tip['medium'].view()

# Rules (5 rules now)


rule1 = [Link](quality['very poor'] | service['very bad'],
tip['low'])
rule2 = [Link](quality['poor'] | service['bad'], tip['low'])
rule3 = [Link](service['decent'], tip['medium'])
rule4 = [Link](service['great'] | quality['amazing'], tip['high'])
rule5 = [Link](service['very great'] | quality['very amazing'],
tip['high'])

# Control system
tipping_ctrl = [Link]([rule1, rule2, rule3, rule4, rule5])
tipping = [Link](tipping_ctrl)

[Link]['quality'] = 5.3
[Link]['service'] = 8.2
#Crunch the number
[Link]()
print([Link]['tip'])
[Link](sim=tipping)

15.047962085308054

You might also like