In [*]: loading

Skip to content
All projects

Machine Learning

Firewall Log Anomaly Detection Using Machine Learning

Hawa Doumbe Traore

Updated 7 Nov 2026

Abstract

This project develops a machine learning system for detecting anomalies in firewall logs. Using the Isolation Forest algorithm, it analyzes 5,250 network records to identify suspicious behavior. The model detects 263 anomalies and 4,987 normal events.

  • Python
  • Pandas
  • NumPy
  • Scikit-learn
  • Isolation Forest
  • Google Colab
  • Machine Learning

1. Problem

Firewall logs contain large amounts of information about network traffic. Manual analysis can make it difficult to quickly identify unusual behavior and potential threats. This project aims to develop a machine learning system that analyzes firewall logs and automatically detects suspicious activities to support network security monitoring.

2. Data

The project uses a dataset containing 5,250 network records, including 5,000 normal events and 250 anomalous events. The original dataset contains 11 fields with no missing values. After preprocessing and feature engineering, 12 features are used, including ports, connection duration, packet count, data volume, and connection rates.

The dataset includes 3,903 TCP records and 1,347 UDP records.

3. Method

The project uses the Isolation Forest algorithm, an unsupervised anomaly detection method.

The methodology includes:

  1. Cleaning and preprocessing network logs.
  2. Selecting and engineering relevant features.
  3. Scaling data using Scikit-learn.
  4. Training Isolation Forest with 200 trees and a contamination rate of 5%.
  5. Detecting anomalies and assigning risk levels.
  6. Saving the trained model, scaler, and detection results.

The implementation was developed in Python using Google Colab.

4. Results

The model analyzed all 5,250 records and identified 263 anomalies (5.01%) and 4,987 events classified as normal.

The resulting risk-level distribution is:

  • Low: 4,987 events
  • Medium: 13 events
  • Critical: 250 events
  • High: 0 events

The system was also tested using normal and anomalous traffic examples. The results demonstrate how Isolation Forest can help identify unusual behavior in firewall logs.

Table 1. Main results.
Metric Value
Firewall logs analyzed 5,250
Features used 12
Isolation Forest estimators 200
Anomalies detected 263
Anomaly detection rate 5.01%
Normal logs 4,987
Screenshot showing merged and shuffled logs, with 5,000 normal records and 250 anomalies.
Figure 1. Normal and anomalous logs are merged into a single dataset and randomly shuffled to prevent ordering bias. The class distribution is then verified: 5,000 normal logs and 250 anomalies, totaling 5,250 records.
Preview of firewall logs showing sample records and the structure of the 5,250-record dataset.
Figure 2. The generated dataset preview displays the first firewall log entries and their structure. It contains 5,250 records across 11 fields. This step helps verify data organization before preprocessing and extracting 12 features.
Screenshot showing the missing values check performed on the firewall log dataset.
Figure 3. A missing values check is performed to identify incomplete fields or absent data in the dataset. This step helps ensure the quality and consistency of firewall logs before preprocessing and applying the Isolation Forest model.
Screenshot showing Isolation Forest initialization and training with 200 trees and a 5% contamination rate.
Figure 4. The Isolation Forest model is initialized with 200 trees and a contamination rate of 5%. The 12 extracted firewall log features are used to train the model using an unsupervised learning approach. It learns to identify unusual patterns and detect potentially suspicious activities.
Chart showing 5,250 analyzed firewall logs, including 263 detected anomalies and 4,987 normal records.
Figure 5. The model analyzes firewall logs and classifies them as normal or anomalous. Out of 5,250 records, it identifies 263 anomalies (5.01%) and 4,987 normal logs (94.99%). Detected anomalies are further classified by risk level: critical or medium.
Chart showing the distribution of 5,250 firewall logs across four risk levels: Low, Medium, High, and Critical.
Figure 6. A classification logic assigns a risk level to each firewall log based on detection results. The records are divided into four categories: Low (4,987), Medium (13), High (0), and Critical (250). This analysis helps identify and prioritize suspicious events.
Screenshot showing examples of generated alert messages.
Figure 7. The system automatically generates security alerts for logs classified as Medium, High, or Critical. Each notification highlights suspicious activity and indicates its risk level, helping administrators monitor and respond to potential security incidents.
Screenshot showing the final dataset exported in CSV format.
Figure 8. After anomaly detection and risk classification, the results are consolidated and exported in CSV format. The final file contains the analyzed logs, predictions, and assigned risk levels. This step completes the analysis pipeline and preserves the results for further examination and use.
Final summary showing detection results, risk distribution, and export of analyzed firewall logs.
Figure 9. The Firewall Log Anomaly Detector uses Isolation Forest to analyze 5,250 firewall logs based on 12 features. The model identifies 263 anomalies (5.01%) and 4,987 normal records. The results are then classified into four risk levels and exported for further analysis.

5. Limitations and future work

The project has some limitations. The model relies on an experimental dataset and a contamination rate set to 5%. Results may vary depending on network traffic patterns and log characteristics. Furthermore, a detected anomaly does not necessarily represent a real cyberattack.

Future work could include:

  • Using logs from real network environments.
  • Comparing Isolation Forest with other anomaly detection algorithms.
  • Improving risk-level classification.
  • Implementing real-time monitoring and automated alerts.
  • Evaluating performance with additional metrics on labeled datasets.

6. References

  1. Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), Article 15. https://doi.org/10.1145/1541880.1541882

  2. Liu, F. T., Ting, K. M., & Zhou, Z.-H. (2008). Isolation Forest. In Proceedings of the Eighth IEEE International Conference on Data Mining (pp. 413–422). IEEE. https://doi.org/10.1109/ICDM.2008.17

  3. Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M., & Duchesnay, É. (2011). Scikit-learn: Machine learning in Python. Journal of Machine Learning Research, 12, 2825–2830. https://jmlr.org/papers/v12/pedregosa11a.html

  4. National Institute of Standards and Technology. (2007). Guide to Intrusion Detection and Prevention Systems (IDPS) (Special Publication 800-94). U.S. Department of Commerce. https://doi.org/10.6028/NIST.SP.800-94

Cite

@misc{traore2026detection,
  author       = {Traore, Hawa Doumbe},
  title        = {{Firewall Log Anomaly Detection Using Machine Learning}},
  year         = {2026},
  howpublished = {\url{https://hawadtraore.alwaysdata.net/en/projects/detection-anomalies-logs-pare-feu}},
  note         = {Case study},
  url          = {https://colab.research.google.com/drive/1PjqNbinaJWzNe0cBxy0eP-qr5yMMOAaI}
}