Skip to content

metedogan/predictive-maintenance

Repository files navigation

Predictive Maintenance

A machine learning project for predicting the Remaining Useful Life (RUL) of aircraft engines using sensor data. The project includes data exploration, preprocessing, model training, and a FastAPI-based REST API for real-time predictions.

Project Overview

This project implements a predictive maintenance solution that analyzes sensor data from aircraft engines to predict their remaining useful life. The solution uses a Random Forest regression model trained on historical sensor readings and provides predictions through a REST API.

Features

  • Data Processing Pipeline: Complete data exploration and preprocessing workflows
  • Machine Learning Model: Random Forest regressor for RUL prediction
  • REST API: FastAPI-based service for real-time predictions
  • Containerization: Docker support for easy deployment
  • Jupyter Notebooks: Interactive analysis and model development

Project Structure

predictive-maintenance/
├── api/                    # FastAPI application
│   └── main.py            # API endpoints and model serving
├── data/                  # Data storage
│   ├── 01_raw/           # Raw datasets
│   └── 02_processed/     # Processed datasets
├── models/               # Trained models and artifacts
│   ├── features.json     # Feature names for model input
│   ├── rf_model.joblib   # Trained Random Forest model
│   └── scaler.joblib     # Data scaler for preprocessing
├── notebooks/            # Jupyter notebooks for analysis
│   ├── 01_data_exploration.ipynb
│   ├── 02_data_preprocessing.ipynb
│   └── 03_modelling.ipynb
├── src/                  # Source code modules
├── Dockerfile           # Container configuration
├── pyproject.toml       # Project dependencies
└── README.md           # This file

Requirements

  • Python 3.10+
  • Dependencies listed in pyproject.toml

Installation

Using uv (recommended)

# Clone the repository
git clone https://github.com/metedogan/predictive-maintenance
cd predictive-maintenance

# Install dependencies
uv sync

Using pip

# Clone the repository
git clone https://github.com/metedogan/predictive-maintenance
cd predictive-maintenance

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -e .

Usage

Running the API

Start the FastAPI server:

uvicorn api.main:app --reload

The API will be available at http://localhost:8000

  • Interactive API documentation: http://localhost:8000/docs
  • Alternative docs: http://localhost:8000/redoc

Making Predictions

Send a POST request to /predict with sensor data:

curl -X POST "http://localhost:8000/predict" \
     -H "Content-Type: application/json" \
     -d '{
       "data": {
         "sensor_2": 643.22,
         "sensor_3": 1589.73,
         "sensor_4": 1402.35,
         "sensor_21": 23.3916
       }
     }'

Response:

{
  "predicted_rul": 142.35
}

Docker Deployment

Build and run the container:

# Build the image
docker build -t predictive-maintenance .

# Run the container
docker run -p 8000:8000 predictive-maintenance

Development

Jupyter Notebooks

The project includes three main notebooks:

  1. 01_data_exploration.ipynb: Initial data analysis and visualization
  2. 02_data_preprocessing.ipynb: Data cleaning and feature engineering
  3. 03_modelling.ipynb: Model training and evaluation

Start Jupyter to explore the notebooks:

jupyter lab notebooks/

Model Training

To retrain the model with new data:

  1. Place raw data in data/01_raw/
  2. Run the preprocessing notebook to generate processed data
  3. Execute the modeling notebook to train and save the new model
  4. The trained artifacts will be saved in the models/ directory

API Endpoints

GET /

Welcome message and API information

POST /predict

Predict remaining useful life from sensor data

Request Body:

{
  "data": {
    "sensor_2": float,
    "sensor_3": float,
    "sensor_4": float,
    // ... other sensor values
    "sensor_21": float
  }
}

Response:

{
  "predicted_rul": float
}

Model Information

  • Algorithm: Random Forest Regressor
  • Input: Sensor readings from aircraft engines
  • Output: Remaining Useful Life (RUL) in cycles
  • Preprocessing: StandardScaler for feature normalization

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages