July 21, 2026
Demystifying Machine Learning classification: from Iris flowers to Cybersecurity
When we talk about Artificial Intelligence, it is easy to get lost in abstract theories and complex mathematical models. However, true…

By Khalida
3 min read
When we talk about Artificial Intelligence, it is easy to get lost in abstract theories and complex mathematical models. However, true understanding comes from getting your hands dirty with real data. Recently, I spent some time working in a cloud-based IDE, interacting with a classification dashboard powered by Scikit-learn, Dash, and the classic Iris dataset.
While classifying flower species based on petal and sepal measurements might seem far removed from analyzing network traffic or hunting for cybersecurity anomalies, the underlying machine learning principles are exactly the same.
In this article, I want to walk you through my practical lab experience and seamlessly unpack the core concepts of machine learning classification, how we train these models, and, most importantly, the mathematical metrics we use to evaluate whether we can actually trust them.
Classification vs. Regression
Before diving into the dashboard, it is crucial to understand what kind of problem we are solving. In machine learning, we generally deal with two main types of predictive models: Classification and Regression.
If my goal was to predict a continuous variable -like estimating the exact number of failed login attempts on a server next week or predicting network bandwidth in Megabytes-I would use Regression. To evaluate a regression model, we measure the error (the difference between the prediction and the actual output) using metrics like Mean Squared Error (MSE = Σ (y_predicted — y_actual)² / n), which severely penalizes large errors by squaring them, or R-squared (R²), which tells us the percentage of variance in the dependent variable that our model can successfully explain.
However, in this lab, the goal wasn't to predict a number. The goal was to map data to a predefined, unordered class: Is this flower a Setosa, Versicolor, or Virginica? This is Classification, and measuring its success requires an entirely different toolkit.
Train/Test Split
You cannot simply feed all your data to an AI model and expect it to perform well in the real world. Doing so leads to overfitting -the model memorizes the data instead of learning the underlying patterns.
Before running the dashboard, the Iris dataset was divided into two distinct parts:
- Training Set: The bulk of the data, used to teach the model with lots of examples.
- Test Set: A portion of data completely hidden from the model during training. This acts as new, unseen data to evaluate how well the model generalizes and performs.
The Lab Experience: Visualizing the Data
Once the environment was launched, I selected two input features: sepal length and petal length. Instantly, a scatter plot generated a visual map of the Test Set.
The plot revealed a fascinating pattern. The green dots representing the Setosa species were clustered far away from the rest. The model had no trouble identifying them. However, the red (Versicolor) and blue (Virginica) dots were overlapping. In real-world scenarios-just like sophisticated malware trying to blend in with normal network traffic -classes are rarely perfectly separated. The model had to draw a mathematical boundary between them, and occasionally, it got confused.
When evaluating the test set, the dashboard proudly displayed an Accuracy of 96.67%. Out of 30 flowers, it guessed 29 correctly. While 97% sounds incredibly reliable, relying solely on accuracy is a dangerous trap, especially in imbalanced datasets. To truly understand the model's performance, we have to analyze its mistakes.
This is where the Confusion Matrix comes into play. It is a matrix that maps Actual values against Predicted values. Looking at the matrix generated by the lab:
- The model correctly identified 11 Setosas, 13 Versicolors, and 5 Virginicas.
- However, it made exactly one mistake: It predicted a flower was a Versicolor, but in reality, it was a Virginica.
This single misclassification trickles down into two highly critical metrics: Precision and Recall.
- Precision: Out of all the times the model claimed a flower was a Versicolor, how often was it correct? Because of that one false claim, the precision for Versicolor dropped to 0.93.
- Recall: Out of all the actual Virginicas that existed in the dataset, how many did the model successfully find? Since it missed one, the recall for Virginica dropped to 0.83.
The F1-Score
In some cases, like patient misdiagnosis or critical threat detection, you cannot afford to sacrifice Precision for Recall, or vice versa. You need a metric that does a great job at balancing both.
This brings us to the F1-Score, which is the harmonic mean of precision and recall. Instead of a simple average, it uses the following formula to ensure that if either Precision or Recall drops significantly, the F1-Score plummets to warn you:
F1-Score = 2 × (Precision × Recall) / (Precision + Recall)
In my lab, despite the slight overlap between classes, the F1-scores remained exceptionally high (above 0.90 across the board), proving that the model was both trustworthy (it rarely cried wolf) and thorough (it rarely missed a target).
Connecting the Dots to Cybersecurity
Why does any of this matter?
Because the mathematical principles governing this Iris dataset are the exact same principles used in modern Security Operations Centers (SOC) and Blue Team environments.
Instead of classifying flowers, we classify behaviors, IPs, and network packets as Benign or Malicious.
- If a threat detection model has low Precision, it will flag normal employee activity as cyberattacks (False Positives). This leads to alert fatigue, burning out security analysts.
- If a model has low Recall, it will miss actual threats (False Negatives), allowing an attacker to bypass defenses unnoticed.
Getting hands-on with ML classification in this lab was an eye-opening experience. It bridged the gap between theoretical math and practical application. Understanding how to navigate a Confusion Matrix and balance an F1-Score is not just a data science skill; it is a foundational necessity for building the next generation of AI-driven cybersecurity defenses.