Downloads · 30 days
0
MeghanaK25/ais-isolation-forest
ais-isolation-forest is a other model from MeghanaK25. Use it for the other task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
A comprehensive suite of unsupervised machine learning models for detecting anomalous vessel behavior in AIS (Automatic Identification System) data, specifically designed for oil spill detection and maritime safety ap…
Downloads · 30 days
0
Access
Public
Updated Sep 12, 2025
Repo size
1.2 MB
Likes
0
Public
Click a slice to open those files.
.pkl1.2 MB · 98%
From the Hugging Face model README
A comprehensive suite of unsupervised machine learning models for detecting anomalous vessel behavior in AIS (Automatic Identification System) data, specifically designed for oil spill detection and maritime safety applications.
This repository contains 5 trained unsupervised anomaly detection models optimized for maritime AIS data analysis:
| Model | Type | Accuracy | Anomaly Rate | Best For | Size |
|---|---|---|---|---|---|
| IsolationForest 🌟 | Ensemble | 100% contamination match | 10.0% | Recommended - Best overall | 1.1MB |
| LocalOutlierFactor | Density-based | 100% contamination match | 10.0% | Local anomaly detection | 104MB |
| OneClassSVM | SVM-based | 100% contamination match | 10.0% | Non-linear patterns | 3.9MB |
| EllipticEnvelope | Statistical | 100% contamination match | 10.0% | Gaussian distributed data | 3.6MB |
| DBSCAN | Clustering | N/A (parameter-free) | 2.1% | Cluster-based anomalies | 39MB |
These models are designed as Step 2A in a comprehensive oil spill detection system:
AIS Stream → Anomaly Detection → Sentinel-1 SAR Analysis → Oil Spill Alert
pip install numpy pandas scikit-learn joblib
import joblib
import numpy as np
# Load the recommended model
model_data = joblib.load('isolationforest_model.joblib')
model = model_data['model']
scaler = model_data['scaler']
# Prepare your AIS data with these features:
# ['sog', 'cog', 'heading', 'width', 'length', 'draught',
# 'navigationalstatus_encoded', 'shiptype_encoded',
# 'speed_category', 'size_category', 'course_diff', 'aspect_ratio']
# Make predictions
features_scaled = scaler.transform(your_ais_features)
anomaly_scores = model.decision_function(features_scaled)
predictions = model.predict(features_scaled)
# Anomalies have prediction = -1, anomaly_score < 0
anomalous_vessels = features_scaled[predictions == -1]
This system contributes to:
Available in both formats for maximum compatibility:
isolationforest_model.pkl (1.1MB) ⭐localoutlierfactor_model.pkl (104MB)oneclasssvm_model.pkl (3.9MB)ellipticenvelope_model.pkl (3.6MB)dbscan_model.pkl (39MB)cd /Users/lakshmikotaru/Documents/ais_isolation_forest
pip install -r requirements.txt
Run the main script to train the Isolation Forest model:
python ais_anomaly_detection.py
This will:
/Users/lakshmikotaru/Downloads/ais_data.csvUse the prediction script to detect anomalies in new data:
# Use with new data file
python predict_anomalies.py path/to/new_ais_data.csv
# Or run without arguments to use original data as example
python predict_anomalies.py
You can adjust the model parameters in ais_anomaly_detection.py:
detector = AISAnomalyDetector(
contamination=0.1, # Expected fraction of anomalies (10%)
random_state=42 # For reproducible results
)
The AIS data should be a CSV file with the following columns:
mmsi: Maritime Mobile Service Identitynavigationalstatus: Current navigation statussog: Speed Over Ground (knots)cog: Course Over Ground (degrees)heading: Vessel heading (degrees)shiptype: Type of vesselwidth: Vessel width (meters)length: Vessel length (meters)draught: Vessel draught (meters)ais_isolation_forest_model.joblibThe trained model file that can be loaded for future predictions.
detected_anomalies.csvDetailed information about all detected anomalies, including:
anomaly_analysis_plots.pngComprehensive visualization showing:
The model may detect:
============================================================
AIS DATA ANOMALY DETECTION USING ISOLATION FOREST
============================================================
Loading data from /Users/lakshmikotaru/Downloads/ais_data.csv...
Loaded 358351 records with 9 columns
Training Isolation Forest model...
Model training completed!
Number of anomalies detected: 35835 out of 358351 samples
Anomaly rate: 10.00%
ANOMALY ANALYSIS SUMMARY
============================================================
Normal samples: 322516 (90.0%)
Anomalous samples: 35835 (10.0%)
To add new derived features, modify the preprocess_data method in the AISAnomalyDetector class.
Adjust the IsolationForest parameters in the __init__ method:
n_estimators: Number of trees in the forestcontamination: Expected proportion of anomaliesmax_samples: Number of samples to draw for each treeModify the visualize_results method to add new plots or change existing ones.
Generated for AIS Anomaly Detection Project - 2025-01-11