Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔮 LSTM-Based Prediction API (Graduation Project)

📌 Overview

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.


🚀 Features

  • 📊 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

🏗️ Tech Stack

  • Python
  • FastAPI
  • TensorFlow / Keras
  • NumPy & Pandas
  • Scikit-learn (Scaler)
  • Uvicorn

⚙️ How It Works

1. Input Data

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]
  ]
}

2. Preprocessing

  • 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

3. Prediction

  • Processed data is passed to the LSTM model

  • Output is rounded to binary (0 or 1)

  • Final result:

    • true → failure expected
    • false → normal behavior

🔌 API Endpoint

POST /predict/

Request Body:

{
  "model_name": "your_model_name",
  "data": [
    ["timestamp", feature1, feature2, ...]
  ]
}

Response:

{
  "prediction": true
}

📂 Project Structure

├── models/        # Saved LSTM models (.h5)
├── scalers/       # Saved scalers (.pkl)
├── main.py        # FastAPI application

▶️ Running the Project

1. Install dependencies

pip install -r requirements.txt

2. Run the server

python main.py

or

uvicorn main:app --reload

🧠 Model Details

  • 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

📌 Notes

  • 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


👩‍💻 My Contribution

  • 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

📈 Future Improvements

  • Add real-time streaming support
  • Improve model accuracy with advanced architectures
  • Add visualization dashboard for predictions

📄 License

This project is part of an academic graduation project and is shared for educational purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages