This project implements an anomaly detection system using two models: the Prophet model developed by Facebook and an LSTM (Long Short-Term Memory) neural network model. By leveraging the strengths of both time-series forecasting and deep learning, this detector aims to identify anomalies efficiently and accurately.
- Prophet Model: A robust procedure for forecasting time series data based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality, plus holiday effects.
- LSTM Model: A type of recurrent neural network (RNN) architecture that excels in learning and remembering over long sequences and is quite effective for time series forecasting.
- Python 3.x
- TensorFlow
- Prophet
- pandas
- numpy
- matplotlib (for visualization, if you're using it)
Note: After installing Anaconda or Miniconda, open the Anaconda Prompt or terminal where conda is accessible to execute the following commands.
-
Navigate to the project directory where the 'requirements.txt' file is located:
cd path/to/your/project_directory
-
Create a new Conda environment. Replace "ENV_NAME" with any name you'd like for the environment, and adjust the Python version if needed:
conda create --name ENV_NAME python=3.9
-
Activate the Conda environment:
conda activate ENV_NAME
Note: Ensure all the following commands are executed within the activated Conda environment.
-
For enhanced performance with the LSTM model, especially if you have a GPU, consider installing both CUDA and cuDNN. These tools optimize neural network computations, making the LSTM model run faster. If you don't have a GPU, you can skip this step:
conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
-
To ensure you have the latest version of pip, which can help in avoiding potential package installation issues and accessing the most recent package releases, execute the following command:
pip install --upgrade pip
-
To set up your environment with all the necessary dependencies, install the packages listed in the 'requirements.txt' file. This ensures that your setup matches the expected versions and packages for the project, minimizing compatibility issues:
pip install -r requirements.txt
Ensure your chosen Integrated Development Environment (IDE) is using the Conda environment you've set up as its Python interpreter.
-
Open the "Preferences" or "Settings" dialog.
-
Navigate to "Project: [Your_Project_Name] > Python Interpreter."
-
In the Python interpreter dropdown, select the Conda environment you've created. If it's not listed:
-
Click on the gear icon or "Add Interpreter" button on the top right.
-
Choose "Add."
-
Select "Conda Environment" on the left, and ensure "Existing environment" is selected.
-
Navigate to and select the Python executable from your Conda environment (usually found in envs/ENV_NAME/bin/python for Unix-like systems or envs\ENV_NAME\python.exe for Windows).
-
Click "OK."
-
-
Open the Command Palette (Ctrl+Shift+P).
-
Search and select "Python: Select Interpreter."
-
Choose the Conda environment you've created from the list.
-
Launch Jupyter Notebook.
-
In the notebook interface, click on the Kernel menu.
-
Select "Change kernel" and choose the Conda environment you've set up.
Note: For other IDEs not listed above, please refer to the respective IDE's documentation on how to set a Python interpreter.
-
Locate the 'data' folder in the project directory. Inside this, you'll find a raw folder.
-
Move your raw data files into the raw folder.
-
In the 'data_preprocessing.py' script, update the file names to match the ones you've added.
The relevant constants to change are:
RAW_TRAIN_PATH = os.path.join(BASE_DIR, "data", "raw", "YOUR_TRAIN_FILE_NAME.csv") RAW_TEST_PATH = os.path.join(BASE_DIR, "data", "raw", "YOUR_TEST_FILE_NAME.csv")
The Anomaly Detector utilizing both the Prophet model and LSTM offers a comprehensive approach to identifying discrepancies in time-series data. By integrating the precision of time-series forecasting with the deep learning capabilities of LSTM, this system serves as a powerful tool for diverse applications. Whether you're new to anomaly detection or seeking an efficient model to improve your existing workflows, this project aims to provide an accessible and accurate solution.