### An Introduction to Fuzzy System **A Case Study with the Iris Dataset** --- #### Iris Dataset Samples | Sepal Length | Sepal Width | Petal Length | Petal Width | Species | |:------------:|:-----------:|:------------:|:-----------:|:------------:| | 5.1 | 3.5 | 1.4 | 0.2 | Setosa | | 4.9 | 3.0 | 1.4 | 0.2 | Setosa | | 7.0 | 3.2 | 4.7 | 1.4 | Versicolor | | 6.4 | 3.2 | 4.5 | 1.5 | Versicolor | | 6.3 | 3.3 | 6.0 | 2.5 | Virginica | | 5.8 | 2.7 | 5.1 | 1.9 | Virginica | --- #### Data Balance Check
--- #### Feature Selection: Data Visualization
SL SW
SL PL
SL PW
SW SL
--- #### Data Visualization (2/3)
SW PL
SW PW
PL SL
PL SW
--- #### Data Visualization (3/3)
PL PW
PW PL
PW SL
PW SW
--- #### Species in PL–PW Space
Note on PCA
--- ### Fuzzy System ``` #Define triangular membership functions petal_length.automf(3) petal_width.automf(3) species['setosa'] = fuzz.trimf(species.universe, [0, 0, 1]) species['versicolor'] = fuzz.trimf(species.universe, [0, 1, 2]) species['virginica'] = fuzz.trimf(species.universe, [1, 2, 2]) #Construct the Fuzzy rules rule1 = ctrl.Rule(petal_length['poor'] & petal_width['poor'], species['setosa']) rule2 = ctrl.Rule(petal_length['average'] & petal_width['average'], species['versicolor']) rule3 = ctrl.Rule(petal_length['good'] & petal_width['good'], species['virginica']) #Consider boundary cases rule4 = ctrl.Rule(petal_length['good'] & petal_width['average'], species['virginica']) rule5 = ctrl.Rule(petal_length['average'] & petal_width['good'], species['virginica']) ``` --- #### PSO Update Equations
$$ x_{i}^{(t+1)} = x_{i}^{(t)} + v_{i}^{(t+1)} $$ $$ v_{i}^{(t+1)} = w \cdot v_{i}^{(t)} + c_1 \cdot r_1 \cdot (p_{i}^{best} - x_{i}^{(t)}) + c_2 \cdot r_2 \cdot (g^{best} - x_{i}^{(t)}) $$ **Where:** - $v_{i}^{(t)}$: velocity of particle $i$ at iteration $t$ - $w$: inertia weight (influences previous velocity) - $c_1$, $c_2$: cognitive and social learning factors - $r_1$, $r_2$: random numbers in [0, 1] - $p_{i}^{best}$: best position found by particle $i$ - $g^{best}$: best position found by the entire swarm - $x_{i}^{(t)}$: current position of particle $i$
---
Image source: Ephramac,
Wikimedia Commons,
CC BY-SA 4.0
--- #### Membership Functions
--- #### Scatter Plot with Bounds
--- #### Fuzzy System 3D
--- #### Confusion Matrix
--- ### Classification Metrics
Class (n)
Precision
Recall
Specificity
Accuracy
F1 Score
setosa (10)
1.00
1.00
1.00
0.97
1.00
versicolor (10)
0.91
1.00
0.95
0.97
0.95
virginica (9)
1.00
0.89
1.00
0.97
0.94
Cost time:2.82 seconds
--- #### Formulas Recap
$$ \text{Precision} = \frac{TP}{TP + FP} $$
$$ \text{Recall} = \frac{TP}{TP + FN} $$
$$ \text{Specificity} = \frac{TN}{TN + FP} $$
$$ \text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN} $$
$$ \text{F1 Score} = 2 \cdot \frac{\text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}} $$
TP
: True Positive
TN
: True Negative
FP
: False Positive
FN
: False Negative
--- ### 10-fold Cross Validation
| Fold | Accuracy (%) | |:----:|:------------:| | 1 | 100.00 | | 2 | 100.00 | | 3 | 100.00 | | 4 | 93.33 | | 5 | 86.67 |
| Fold | Accuracy (%) | |:----:|:------------:| | 6 | 100.00 | | 7 | 100.00 | | 8 | 100.00 | | 9 | 100.00 | | 10 | 92.86 |
**10-fold CV average accuracy:** 97.29% ± 4.47% --- #### It's All About the Function
---
#### Universal Approximation Theorem $$ \forall \epsilon > 0, f \in C(K, \mathbb{R}^m),K \subset \mathbb{R}^n\ \text{compact}, $$ $$ \exists F: \mathbb{R}^n \to \mathbb{R}^m\ \text{(NN)}\, $$ $$ \ni |F(x) - f(x)| < \epsilon, \forall x \in K $$ --- Thank you!