- Project Overview
- Problem Statement
- Solution Summary
- Tech Stack
- Project Architecture
- Deployment Architecture
- Pipelines
- Constants & Configuration
- How to Run
- Artifacts & Outputs
- Repository Structure (Important Folders)
- License
Sensor-Fault-Detection is an end-to-end Machine Learning (ML) project that detects sensor/component faults related to a truck’s Air Pressure System (APS) using historical sensor readings.
Who this is for
- ML Engineers / Data Scientists who want a production-style pipeline (ingestion → validation → transformation → training → evaluation → model push).
- MLOps practitioners looking for a structured codebase with artifacts, configuration, and modular components.
- Reliability / Fleet / Maintenance teams who need early detection to reduce downtime and avoid unnecessary repairs.
Data: Sensor Data
- The system in focus is the Air Pressure System (APS), which generates pressurized air used in various truck functions such as braking and gear changes.
- The dataset positive class corresponds to component failures for a specific component of the APS system.
- The dataset negative class corresponds to trucks with failures for components not related to the APS system.
The goal is to reduce the cost due to unnecessary repairs, so it is required to minimize false predictions.
Misclassification costs are defined as:
- Cost_1 = 10: cost of an unnecessary check by a mechanic at a workshop
- Cost_2 = 500: cost of missing a faulty truck, which may cause a breakdown
| True Class \ Predicted Class | Positive | Negative |
|---|---|---|
| Positive | — | cost_2 |
| Negative | cost_1 | — |
The total cost of a prediction model is:
The total cost of a prediction model is:
Total Cost = Cost_1 *(Number of Type-1 Failures) + Cost_2 * (Number of Type-2 Failures)
Total Cost = 10 *(Number of Type-1 Failures) + 500 * (Number of Type-2 Failures)
Where, in this context:
- Type-1 corresponds to false positives (unnecessary workshop check)
- Type-2 corresponds to false negatives (missed APS-related failure)
From the above, we must reduce both false positives and false negatives.
However, it is more important to reduce false negatives, since the cost incurred due to a false negative is 50× higher than the cost of a false positive.
- Need to handle many null values in almost all columns
- No low-latency requirement
- Interpretability is not important
- Misclassification leads to unnecessary repair costs
This repository implements:
-
A Training Pipeline that:
- Ingests sensor data (e.g., from DB/source files)
- Validates it against a schema
- Transforms/preprocesses features
- Trains a model
- Evaluates against an existing/baseline model (typical champion–challenger pattern)
- Pushes the approved model to a serving location (e.g., S3/model registry)
-
A Prediction Pipeline that:
- Loads the latest pushed model
- Applies the same preprocessing
- Produces predictions for new sensor records
Note: Some choices are inferred from repository structure. Exact versions and libraries are defined in
requirements.txt.
| Category | Tools / Libraries (Typical) |
|---|---|
| Language | Python |
| Data | pandas, numpy |
| ML | scikit-learn (typical for tabular classification) |
| Serialization | pickle / joblib (typical) |
| Validation | schema-driven validation (see config/schema.yaml) |
| Database / Source | MongoDB (see sensor/configuration/mongo_db_connection.py) |
| Cloud / Model Storage | S3 (constants present in sensor/constant/s3_bucket.py) |
| Packaging | setup.py, Sensor.egg-info/, dist/ |
This project is organized around pipeline components (ingestion, validation, transformation, etc.), with shared entities/config/constants and a training pipeline orchestrator.
Key modules (high-level):
sensor/components/: Pipeline components that generate and consume artifactssensor/pipeline/: Pipeline orchestration (training workflow)sensor/entity/: Strongly-typed artifact/config entities passed between stepssensor/ml/: Model and metric utilities (training/evaluation/prediction helpers)sensor/constant/: Centralized constants for paths, env vars, DB, S3, pipeline settingsconfig/schema.yaml: Dataset schema and validation rules
A typical deployment flow for this repository looks like:
- Training is executed (locally/CI) to produce a validated model.
- The approved model is pushed to a storage layer (commonly S3 or a registry).
- A prediction service (batch job, API, or scheduled pipeline) loads the pushed model and runs inference on incoming data.
Assumption (based on repo structure): model artifacts are stored locally and/or pushed to an S3 bucket using parameters defined in
sensor/constant/s3_bucket.py.
The training pipeline is a sequence of components that progressively turn raw sensor data into a validated, evaluated, and deployable model.
Definition
- The orchestrated workflow that runs all training components end-to-end and manages artifacts between steps.
Inputs
- Data source configuration (DB/S3/local depending on configuration)
- Schema definition:
config/schema.yaml - Pipeline configuration and environment variables
Process / Steps
- Start pipeline run
- Ingest raw data
- Validate data (schema + quality checks)
- Transform data (preprocessing/feature engineering)
- Train a model
- Evaluate against acceptance criteria / existing model
- Push model to serving location (local registry/S3)
Outputs / Artifacts
- Ingestion artifacts (raw dataset snapshot)
- Validation reports
- Transformed datasets + preprocessing objects
- Trained model artifact
- Evaluation report
- Pushed model package (ready for inference)
Where in code
- Orchestration:
sensor/pipeline/training_pipeline.py - Entry point (typical):
main.py
Definition
- Collects raw sensor data from the configured source and writes it to an artifact location for downstream steps.
Inputs
- Data source settings (commonly MongoDB connection and collection details)
- Pipeline run configuration (artifact directories, file naming)
Process / Steps
- Connect to data source
- Read raw records (tabular sensor dataset)
- Store raw dataset snapshot (e.g., CSV/Parquet) for reproducibility
- Return ingestion artifact metadata (paths, counts)
Outputs / Artifacts
- Raw dataset file(s)
- Ingestion metadata (e.g., path references, record counts)
Where in code
sensor/components/data_ingestion.py
Definition
- Ensures ingested data matches expected structure and basic quality rules before training.
Inputs
- Ingested raw dataset artifact
- Schema definition:
config/schema.yaml
Process / Steps
- Validate columns and expected feature set
- Validate data types / basic constraints (as defined by schema)
- Check dataset drift or statistical changes (typical in production pipelines)
- Generate validation reports for traceability
Outputs / Artifacts
- Validation status (pass/fail)
- Validation report(s) (e.g., JSON/YAML/text)
- Drift report(s) (if implemented)
Where in code
- Component:
sensor/components/data_validation.py - Schema:
config/schema.yaml
Definition
- Converts validated raw data into model-ready features using preprocessing steps.
Inputs
- Validated dataset artifact
- Transformation configuration (feature handling rules, target column info)
Process / Steps
- Split features/target
- Handle missing values (imputation strategies are common for sensor datasets)
- Encode/scale features (as needed for the chosen model)
- Save transformation pipeline/preprocessor object
- Output transformed train/test datasets
Outputs / Artifacts
- Transformed training dataset
- Transformed test/validation dataset
- Saved preprocessing object (transformer/pipeline)
Where in code
sensor/components/data_transformation.py
Definition
- Trains a classification model to predict APS-related failures from transformed sensor features.
Inputs
- Transformed datasets (train/test)
- Training configuration (algorithm parameters, scoring metric, thresholds)
Process / Steps
- Load transformed training data
- Train candidate model(s)
- Compute training metrics (and optionally cross-validation metrics)
- Persist the trained model artifact for evaluation
Outputs / Artifacts
- Trained model object/package
- Training metrics summary
Where in code
sensor/components/model_trainer.py
Definition
- Compares the newly trained model against baseline criteria and/or a previously deployed model to decide if it should be promoted.
Inputs
- Newly trained model artifact
- Test dataset artifact
- (Optional) Existing “production” model artifact (for comparison)
- Evaluation criteria (metric thresholds, acceptance rules)
Process / Steps
- Load candidate model and evaluation dataset
- Compute evaluation metrics (e.g., precision/recall/F1/ROC-AUC; cost-aware metrics may be used)
- Compare candidate vs. current model (if available)
- Generate evaluation report and a promotion decision
Outputs / Artifacts
- Evaluation report (metrics + decision)
- Best-model selection decision (promote/reject)
Where in code
sensor/components/model_evaluation.py
Definition
- Publishes the approved model to a target location for inference (local model registry and/or S3 bucket).
Inputs
- Approved model artifact
- Push destination configuration (paths, bucket settings, versioning)
Process / Steps
- Validate that the model is approved for pushing
- Copy/package the model to the “serving” directory or registry path
- (Optional) Upload model artifacts to S3
- Record pushed model metadata (version/path)
Outputs / Artifacts
- Pushed model package (servable)
- Push metadata (destination path, version)
Where in code
sensor/components/model_pusher.py
Definition
- The inference workflow that loads the latest pushed model and generates predictions for new sensor data records.
Inputs
- Incoming sensor data (commonly a CSV file, dataframe, or API payload)
- Latest pushed model artifact (and preprocessing object)
Steps
- Read input data
- Load the pushed model + transformer/preprocessor
- Apply the same transformations used during training
- Generate predictions (class + optionally probability/score)
- Return or save results
Outputs
- Predictions (e.g.,
faultvsno_fault, or class labels) - Optional probability scores and a prediction report file
Where prediction logic lives (by repo structure)
- Entry point (typical):
main.py - Model utilities (typical):
sensor/ml/model/ - Shared utilities:
sensor/utils/andsensor/utils/main_utils.py
What these constants/configs are used for
- Paths & artifact directories (where ingestion/validation/transformation outputs are stored)
- Database configuration (MongoDB connectivity and collection settings)
- Environment variables (secrets/URLs/keys are typically injected via env vars)
- Cloud bucket configuration (S3 bucket names, prefixes, model registry paths)
- Pipeline settings (training pipeline naming, run IDs, default locations)
Relevant modules
sensor/constant/application.pysensor/constant/database.pysensor/constant/env_variable.pysensor/constant/s3_bucket.pysensor/constant/training_pipeline/
Commands below reflect typical usage for a repository structured like this. Adjust if your
main.pyexposes different CLI arguments or modes.
git clone <YOUR_REPO_URL>
cd Sensor-Fault-Detectionpython -m venv .venv
# Linux/Mac
source .venv/bin/activate
# Windows (PowerShell)
# .venv\Scripts\Activate.ps1
pip install -r requirements.txtThis project includes modules for MongoDB and S3-style storage. Export environment variables as needed for your setup.
Typical placeholders (do not hardcode secrets):
MONGODB_URL(or similar): MongoDB connection stringMONGODB_DATABASE_NAMEMONGODB_COLLECTION_NAMEAWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGIONS3_BUCKET_NAME(or equivalent used bysensor/constant/s3_bucket.py)- Any pipeline/runtime variables referenced in
sensor/constant/env_variable.py
Example (Linux/Mac):
export MONGODB_URL="mongodb+srv://<user>:<password>@<cluster>/<db>"
export MONGODB_DATABASE_NAME="<database>"
export MONGODB_COLLECTION_NAME="<collection>"
export AWS_ACCESS_KEY_ID="<key>"
export AWS_SECRET_ACCESS_KEY="<secret>"
export AWS_DEFAULT_REGION="<region>"
export S3_BUCKET_NAME="<bucket>"Typical usage:
python main.pyIf your main.py supports modes (train/predict), it may look like:
python main.py trainTypical usage (may vary by implementation):
python main.py predict --input <path_to_input_csv> --output <path_to_predictions_csv>- Artifacts are typically written to a pipeline artifact directory (often under a project-level folder like
artifact/,artifacts/, or a configured path). - Logs are typically written according to
sensor/logger.pyconfiguration (console + file logging depending on setup).
Assumption: artifact locations are controlled by constants in
sensor/constant/and entities insensor/entity/.
Below are typical artifacts produced by each pipeline stage (names/paths depend on your config/constants):
| Stage | Typical Artifacts Produced |
|---|---|
| Ingestion | Raw dataset snapshot (CSV/Parquet), ingestion metadata (record counts, file paths) |
| Validation | Validation status, schema check report, drift/quality report (if implemented) |
| Transformation | Transformed train/test arrays/files, saved preprocessing object (transformer/pipeline) |
| Training | Trained model artifact, training metrics summary |
| Evaluation | Evaluation report (metrics + promotion decision), comparison with existing model (if available) |
| Pusher | “Servable” model package in a registry directory and/or uploaded to S3, push metadata (version/path) |
Sensor-Fault-Detection/
├── .gitignore
├── .gitmodules
├── Flowcharts/
│ ├── 0_Sensor_Training_Pipeline.png
│ ├── 1_Sensor_Data_Ingestion_Component.png
│ ├── 2_Sensor_Data_Validation_Component .png
│ ├── 3_Sensor_Data_Transformation_Component.png
│ ├── 4_Sensor_Model_Trainer_Component.png
│ ├── 5_Sensor_Model_Evaluation_Component.png
│ ├── 6_Sensor_Model_Pusher_Component.png
│ ├── 7_Sensor_Prediction_Pipeline.png
│ ├── Constant.png
│ ├── Deployment_Archietecture.png
│ └── Project_Archietecture.png
├── LICENSE
├── Notebook/
│ ├── Scania_APS_failure_prediction.ipynb
│ └── aps_failure_training_set1.csv
├── README.md
├── Sensor.egg-info/
├── build/
├── config/
│ └── schema.yaml
├── dist/
├── main.py
├── requirements.txt
├── sensor/
│ ├── cloud_storage/
│ ├── components/
│ │ ├── data_ingestion.py
│ │ ├── data_transformation.py
│ │ ├── data_validation.py
│ │ ├── model_evaluation.py
│ │ ├── model_pusher.py
│ │ └── model_trainer.py
│ ├── config.py
│ ├── configuration/
│ │ └── mongo_db_connection.py
│ ├── constant/
│ │ ├── application.py
│ │ ├── database.py
│ │ ├── env_variable.py
│ │ ├── s3_bucket.py
│ │ └── training_pipeline/
│ ├── data_access/
│ │ └── sensor_data.py
│ ├── entity/
│ │ ├── artifact_entity.py
│ │ └── config_entity.py
│ ├── exception.py
│ ├── logger.py
│ ├── ml/
│ │ ├── metric/
│ │ └── model/
│ ├── pipeline/
│ │ └── training_pipeline.py
│ ├── utils.py
│ └── utils/
│ └── main_utils.py
└── setup.py
-
sensor/components/- Individual pipeline steps (ingestion, validation, transformation, training, evaluation, pushing).
- Each component typically reads an input artifact and produces an output artifact.
-
sensor/pipeline/- Pipeline orchestration logic (end-to-end training workflow).
-
sensor/entity/- Definitions of structured entities:
- Config entities (what parameters a component needs)
- Artifact entities (what a component produces for downstream steps)
- Definitions of structured entities:
-
sensor/ml/- Model and metric utilities used during training/evaluation/prediction.
-
config/- Central configuration files such as
schema.yamlused by validation.
- Central configuration files such as
-
Notebook/- Experimentation notebook and a sample dataset file for exploration/training reference.
-
Flowcharts/- Visual documentation for architecture and each pipeline component.
See LICENSE.











