This project is an advanced anomaly detection system designed to identify subtle anomalies in high-dimensional, noisy datasets. It leverages a deep autoencoder model to detect deviations from normal behavior and provides contextual insights into the detected anomalies. The system is built using TensorFlow for model training and Streamlit for deployment and visualization.
-
Subtle Anomaly Detection:
- Detects anomalies that deviate slightly from normal behavior, even in noisy data.
- Uses a deep autoencoder model for robust pattern recognition.
-
Contextual Insights:
- Provides domain-specific interpretation of anomalies.
- Differentiates between benign variations and potential risks.
-
Scalable and Efficient:
- Processes large datasets in chunks to handle memory constraints.
- Dynamically adjusts anomaly thresholds based on data patterns.
-
Interactive Visualization:
- Visualizes reconstruction errors and anomaly distributions.
- Provides feature importance analysis to understand contributing factors.
The project uses the Tennessee Eastman Process (TEP) Dataset, which is a simulated industrial process control dataset with faults for anomaly detection. The dataset can be downloaded from Harvard Dataverse.
The dataset includes:
TEP_FaultFree_Training.csv: Training data with normal behavior.TEP_FaultFree_Testing.csv: Testing data with normal behavior.TEP_Faulty_Training.csv: Faulty data for anomaly detection.TEP_Faulty_Testing.csv: Faulty data for anomaly detection.
- Clone the repository:
git clone https://github.com/djdiptayan1/AnomalyDetection.git cd AnomalyDetection - Install the required dependencies:
pip install -r requirements.txt
- Download the dataset from the Harvard Dataverse and place the CSV files in the
data/folder.
To train the autoencoder model, you can either:
- Run the Jupyter notebook:
jupyter notebook train.ipynb
- Or run the Python script:
python train_model.py
This will:
- Preprocess the data.
- Train the autoencoder model.
- Save the trained model (
autoencoder.h5) and scaler (scaler.npy) in themodels/folder.
To detect anomalies in a dataset, you can either:
- Run the Jupyter notebook:
jupyter notebook detect.ipynb
- Or run the Python script:
python detect_anomalies.py
This will:
- Load the trained model and scaler.
- Process the dataset in chunks to detect anomalies.
- Save the results with anomaly flags in
data/TEP_Faulty_Testing_Anomalies.csv.
To launch the interactive Streamlit app, run:
streamlit run app.pyThis will:
- Start a local server and open the app in your browser.
- Allow you to upload datasets, detect anomalies, and visualize results interactively.
- The dataset is normalized using
MinMaxScalerto ensure all features are on the same scale. - The first column (index) is dropped if present.
A deep autoencoder is used to learn the normal behavior of the data. The model consists of:
- Input layer: Same size as the number of features.
- Hidden layers: Two dense layers with ReLU activation.
- Output layer: Reconstructs the input with sigmoid activation.
- The reconstruction error (Mean Squared Error) is calculated for each data point.
- Anomalies are flagged if the reconstruction error exceeds a dynamic threshold (mean + 3 × standard deviation).
- Reconstruction error distribution is plotted as a histogram.
- Anomalies are visualized over time (if a time column exists).
- Feature importance is analyzed to understand contributing factors.
The project is deployed using Streamlit, which provides an interactive web interface for anomaly detection. To deploy the app:
- Install Streamlit:
pip install streamlit
- Run the app:
streamlit run app.py
- Access the app via the provided URL in your browser.
DEMO LINK: https://drive.google.com/file/d/1viMe4T57VdVZgvWfiWqNqthc1ZN_pdvn/view?usp=sharing
The system provides:
- Accurate anomaly detection: Identifies subtle deviations in noisy data.
- Contextual insights: Differentiates between benign variations and critical anomalies.
- Scalable processing: Handles large datasets efficiently using chunk-based processing.
- Sushant Chavan
- Diptayan Jash
- Gaurav Mishra
- Utkarsh Jaiswal
- Tennessee Eastman Process Dataset: Provided by Harvard Dataverse.
- TensorFlow: For building and training the autoencoder model.
- Streamlit: For deploying the interactive web app.
For questions or feedback, please contact sushantchavan920@gmail.com.