This project is a time-series prediction API built using LSTM (Long Short-Term Memory) models to detect potential failures based on sequential data.
It is part of a larger graduation project for predictive analysis, where the system processes timestamped input data and returns a prediction indicating whether a failure is expected.
- 📊 Time-series preprocessing with dynamic windowing
- 🧠 LSTM model for sequential prediction
- ⚡ FastAPI-based REST API
- 🔄 Model & scaler loading with caching for performance
- 📈 Custom F1-score loss function
- Python
- FastAPI
- TensorFlow / Keras
- NumPy & Pandas
- Scikit-learn (Scaler)
- Uvicorn
The model receives data in the form:
- Timestamp (string)
- Feature values (floats)
Example:
{
"model_name": "model1",
"data": [
["2024-01-01 10:00:00", 0.5, 1.2],
["2024-01-01 10:01:00", 0.6, 1.1]
]
}- Converts timestamps to milliseconds
- Splits data into time-based windows (20 minutes)
- Applies padding to ensure fixed input size
- Scales features using a pre-trained scaler
-
Processed data is passed to the LSTM model
-
Output is rounded to binary (0 or 1)
-
Final result:
true→ failure expectedfalse→ normal behavior
{
"model_name": "your_model_name",
"data": [
["timestamp", feature1, feature2, ...]
]
}{
"prediction": true
}├── models/ # Saved LSTM models (.h5)
├── scalers/ # Saved scalers (.pkl)
├── main.py # FastAPI application
pip install -r requirements.txtpython main.pyor
uvicorn main:app --reload- Architecture: LSTM (for time-series data)
- Input: Sequential windows of sensor/features data
- Output: Binary classification (failure / no failure)
- Loss Function: Custom F1 Loss for better imbalance handling
-
Models and scalers must exist in:
models/scalers/
-
Each model requires a corresponding scaler with the same name
-
Input data must cover sufficient time range to form valid windows
- Designed and implemented the prediction API using FastAPI
- Built the data preprocessing pipeline for time-series windowing
- Integrated LSTM model inference with scaling and padding
- Implemented model caching for performance optimization
- Add real-time streaming support
- Improve model accuracy with advanced architectures
- Add visualization dashboard for predictions
This project is part of an academic graduation project and is shared for educational purposes.