fuzzylogic
fuzzylogic
import pandas as pd
service = 7
degrees = {
'Poor': poor(service),
'Average': average(service),
'Good': good(service)
classification = df['Degree'].idxmax()
# Output
python
CopyEdit
import numpy as np
import pandas as pd
We use:
NumPy for math (not used much here, but good for future extensions).
python
CopyEdit
service = 7
This is the input — a number from 0 to 10 that represents the quality of service.
These are triangular functions. They return a degree of membership between 0 and 1.
python
CopyEdit
def poor(x):
If x = 5, output = 0.
python
CopyEdit
def average(x):
python
CopyEdit
def good(x):
If x = 5, output = 0.
If x = 10, output = 1.
python
CopyEdit
degrees = {
'Poor': poor(service),
'Average': average(service),
'Good': good(service)
This dictionary stores the degree to which the input value belongs to each category.
Example if service = 7:
python
CopyEdit
degrees = {
'Poor': 0.0,
'Average': 0.2,
'Good': 0.4
python
CopyEdit
We turn the dictionary into a Pandas DataFrame, which looks like this:
Degree
Poor 0.00
Average 0.20
Good 0.40
python
CopyEdit
classification = df['Degree'].idxmax()
So in our example:
python
CopyEdit
You'll get:
yaml
CopyEdit
✅ Summary
No external libraries,
No defuzzification,