How 03-princy/employee-salary-prediction works
Project type and purpose
• Type: A lightweight machine-learning service for predicting employee salary based on the UCI Adult dataset.
• Purpose: Train a predictive model (using train_model.py and notebooks), serialize artifacts (best_model.pkl, target_encoder.pkl), and expose an inference endpoint (via app.py).
File structure
• Root files:
– adult.csv: raw dataset
– train_model.py: training pipeline script
– best_model.pkl, target_encoder.pkl: serialized artifacts
– app.py: Flask (or similar) inference API
– Jupyter notebooks: exploratory data analysis and iterative model building
• No separate “frontend” directory, so the inference surface is a simple HTTP API.
Main components & interactions
a. Data Source
– adult.csv (raw input)
b. Training Pipeline
– train_model.py (ingests adult.csv)
– Preprocessor (target_encoder.pkl)
– Model Trainer (e.g., scikit-learn pipeline)
– Model Selection → best_model.pkl
c. Model Storage
– best_model.pkl, target_encoder.pkl (persisted to disk)
d. Inference Service
– app.py loads both pickles at startup
– Exposes HTTP endpoint (e.g., POST /predict)
– Input JSON → preprocess → model.predict() → output JSON
e. (Optional) Client
– Any HTTP client (curl, Postman, front-end) that consumes /predict
Architectural patterns & design principles
• Separation of concerns: training vs. inference
• Artifact versioning: keeping best_model.pkl separate from code
• Lightweight microservice: single-process web API
• Reproducibility: notebooks for EDA, train_model.py for pipeline
• Clear labels: “Raw Dataset,” “Preprocessor,” “Model Trainer,” “best_model.pkl,” “target_encoder.pkl,” “Flask API (app.py).”
• A note indicating that “adult.csv” lives on disk alongside code.
[Raw Dataset (adult.csv)]
│
▼ ingest
[Training Pipeline (train_model.py)]──►[target_encoder.pkl]
│ │
└──►[best_model.pkl]◄────────────────┘
│
▼ load on startup
[Inference Service (app.py) ──► HTTP API /predict ──► Client]