This repository provides a modular, production-quality MLOps pipeline for Spotify music popularity prediction, built as part of an academic project in MLOps fundamentals. The codebase is designed to bridge the gap between research prototypes (Jupyter notebooks) and scalable, maintainable machine learning systems in production.
Phase 1: Modularization, Testing, and Best Practices
- Jupyter notebook translated into well-documented, test-driven Python modules
- End-to-end pipeline: data ingestion, validation, preprocessing, feature engineering, model training, evaluation, and batch inference
- Robust configuration via
config.yamland reproducibility through explicit artifact management - Extensive unit testing with pytest (89 total tests)
- Strict adherence to software engineering and MLOps best practices
Phase 2: Hydra, MLflow, and W&B Integration
- All pipeline steps now execute as MLflow runs
- Dynamic configuration managed with Hydra
- Metrics and artifacts automatically logged to Weights & Biases
- Automated training pipeline with CI/CD workflows
Phase 3: CI/CD and FastAPI Serving
- GitHub Actions workflow with automated testing and linting
- FastAPI application (
app/main.py) exposes prediction and health endpoints - Includes
/predict_batchroute for validating and scoring multiple records - Docker containerization for scalable deployment
.
βββ README.md
βββ config.yaml # Central pipeline configuration
βββ environment.yml # Reproducible conda environment
βββ conda.yaml # MLflow conda environment
βββ dvc.yaml # Data Version Control pipeline
βββ Dockerfile # Container deployment
βββ data/
β βββ raw/ # Original Spotify songs dataset
β βββ raw_holdout/ # Holdout data for inference testing
β βββ processed/ # Intermediate processed datasets
β βββ predictions/ # Model prediction outputs
βββ models/ # Serialized models and preprocessing artifacts
βββ logs/ # Pipeline execution logs and validation reports
βββ app/
β βββ main.py # FastAPI application for model serving
βββ .github/workflows/ # GitHub Actions CI/CD pipeline
βββ src/
β βββ data_load/ # Data ingestion utilities
β βββ data_validation/ # Schema and data quality validation
β βββ preprocess/ # Data preprocessing and scaling
β βββ features/ # Feature engineering (polynomial, genre parsing)
β βββ model/ # Model training with stepwise selection
β βββ evaluation/ # Model evaluation and metrics calculation
β βββ inference/ # Batch inference with prediction intervals
β βββ main.py # Pipeline orchestrator
βββ tests/ # Comprehensive unit and integration tests
Artifact paths in config.yaml such as data/processed, models/, and logs/ are resolved relative to this project root. Generated metrics, preprocessing pipelines, and trained models are versioned and stored under these directories.
The pipeline predicts Spotify track popularity (0-100 scale) based on audio features and metadata. It applies rigorous validation and modular design suitable for research, teaching, and real-world deployment scenarios.
| Feature | Description | Type | Range/Values |
|---|---|---|---|
| track_popularity | Target variable: Spotify popularity score | int | 0-100 |
| danceability | How suitable a track is for dancing | float | 0.0-1.0 |
| energy | Perceptual measure of intensity and power | float | 0.0-1.0 |
| loudness | Overall loudness of track in decibels | float | min: -60.0 |
| speechiness | Presence of spoken words in a track | float | 0.0-1.0 |
| acousticness | Confidence measure of whether track is acoustic | float | 0.0-1.0 |
| liveness | Detects presence of audience in recording | float | 0.0-1.0 |
| valence | Musical positiveness conveyed by track | float | 0.0-1.0 |
| tempo | Overall estimated tempo in beats per minute | float | min: 0.0 |
| duration_ms | Track duration in milliseconds | float | min: 0.0 |
| artist_popularity | Popularity of the artist | int | 0-100 |
| key | Key the track is in (using standard Pitch Class notation) | float | 0.0-11.0 |
| mode | Major (1) or minor (0) modality | float | 0.0-1.0 |
| artist_genres | List of genres associated with the artist | str | Genre strings |
Engineered features include genre dummy variables and polynomial combinations of audio features.
- Single entry point orchestrating the entire MLOps workflow
- Supports configurable pipeline stages via Hydra configuration
- MLflow project execution with parameter passing and artifact tracking
- Robust logging and error handling for production environments
- Loads Spotify songs data from CSV with configurable parameters
- Environment variable management for secure configurations
- Comprehensive error handling and logging
- Schema validation: column types, ranges, missing values, data quality checks
- Configurable strictness:
raiseorwarnon validation errors - Detailed validation reports (JSON) with HTML summaries logged to W&B
- Ensures data integrity throughout the pipeline
- Raw data cleaning and outlier removal using IQR method
- Train/test/holdout splitting with stratification
- Feature scaling (MinMax/Standard) with sklearn pipelines
- Creates inference holdout set for unbiased evaluation
- Genre parsing from artist metadata into dummy variables
- Polynomial feature generation for audio features interaction
- Configurable feature selection and exclusion rules
- Feature importance tracking and documentation
- Linear regression with stepwise feature selection using statsmodels
- Automated feature selection based on statistical significance
- Model registry supporting multiple algorithms (easily extensible)
- Hyperparameter tracking and model versioning
- Comprehensive regression metrics: RMSE, MAE, RΒ², Adjusted RΒ²
- Residual analysis and prediction interval calculations
- Model performance visualization and reporting
- Statistical validation of model assumptions
- Loads preprocessing and model artifacts for new data prediction
- Applies identical transformations to ensure consistency
- Generates predictions with 95% confidence intervals
- Exports results with original data for analysis
- Comprehensive pytest suite covering all modules (89 total tests)
- Mock data generation for isolated testing
- CI/CD integration with coverage requirements
- config.yaml: Centralized configuration for all pipeline parameters
- environment.yml: Reproducible Conda environment with exact versions
- MLflow Projects: Reproducible pipeline execution with parameter tracking
- W&B Artifacts: Versioned data, models, and experiment artifacts
- Hydra: Dynamic configuration overrides and environment management
Environment setup:
# Clone repository
git clone https://github.com/adriansotomora/mlops_group8.git
cd mlops_group8
# Create and activate conda environment
conda env create -f environment.yml
conda activate group8_full
# Set up environment variables (optional - values also configured in config.yaml)
# Create .env file with your Weights & Biases credentials:
# WANDB_API_KEY=your_wandb_api_key
# Alternatively, update config.yaml with your WANDB_ENTITY
# Authenticate with Weights & Biases
wandb loginRun end-to-end pipeline:
# Run complete pipeline using MLflow (recommended)
mlflow run . -P steps=all
# Run via Python with Hydra
python main.py main.steps=all
# Run specific stages
mlflow run . -P steps="preprocess,features,model"
# Run with hyperparameter overrides using MLflow
mlflow run . -e main_with_override -P steps=all -P hydra_options="model.linear_regression.stepwise.threshold_in=0.01"All steps automatically log metrics and artifacts to W&B. The pipeline creates a holdout dataset during preprocessing for unbiased inference testing.
Run inference:
# Batch inference on new data
python src/main.py main.steps=inference
# Direct inference script
python -m src.inference.inferencer --input data/raw_holdout/inference_holdout_data.csv --output data/predictions/results.csvServe model via FastAPI:
# Start API server
uvicorn app.main:app --host 0.0.0.0 --port 8000
# Test single prediction
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{
"artist_popularity": 63,
"genre": "rock",
"danceability": 0.735,
"energy": 0.578,
"liveness": 0.0985,
"loudness": -11.84,
"speechiness": 0.0596,
"tempo": 75.0,
"valence": 0.471,
"duration_ms": 207959.0,
"acousticness": 0.514,
"key": 1.0
}'Run tests:
# Run all tests with coverage
pytest --cov=src --cov-report=term-missing
# Run linting
flake8 .Before building, set environment variables in .env:
WANDB_PROJECT=mlops_group8
WANDB_ENTITY=your-entity
WANDB_API_KEY=your-api-keyBuild and run Docker container:
# Build image
docker build -t spotify-popularity-api .
# Run container
docker run --env-file .env -p 8000:8000 spotify-popularity-apiThe server automatically detects the PORT environment variable, making it compatible with cloud platforms like Render, Heroku, or AWS ECS.
- Model Enhancement: Implement additional algorithms (Random Forest, XGBoost) based on current model registry
- Model Monitoring: Enhance logging and metrics tracking for production deployments
- Automated Deployment: Extend CI/CD pipeline for automatic model deployment
- Feature Store: Centralized feature management and versioning
- Performance Optimization: Pipeline efficiency improvements and caching
- Course: MBD-EN2024ELECTIVOS-MBDMCSBT_38E88_467445 - MLOPS: MACHINE LEARNING OPERATIONS
- Institution: IE University
- Best Practices: Demonstrates academic excellence in MLOps engineering, suitable for production deployment
- Extensibility: Configuration-driven architecture enables easy extension for advanced MLOps topics
- Assessment: Comprehensive test suite and documentation support peer evaluation and grading
- Pipeline Modularization: Jupyter notebook β Production-ready modules
- MLOps Toolchain: MLflow, W&B, Hydra integration
- CI/CD Implementation: Automated testing and deployment
- Model Serving: RESTful API with FastAPI
- Reproducibility: Environment and experiment management
Group 8 Members:
- ADRIAN SOTO MORA
- MANUEL EDUARDO BONNELLY SANCHEZ
- SERGIO LEBED WRIGHT
- YEABSIRA SELESHI
- HIROMITSU FUJIYAMA
Course Information:
- Institution: IE University
- Program: Master in Big Data & Analytics
- Course: MLOPS: Machine Learning Operations
- Academic Year: 2024-2025
Acknowledgments:
- Course instructors for MLOps fundamentals and best practices
- Spotify for providing rich audio feature datasets
- Open-source MLOps community for tools and methodologies
This project is developed for academic and educational purposes as part of the IE University MLOps course.
Academic Use License:
- β Educational and research use permitted
- β Code sharing within academic community encouraged
- β Modification and extension for learning purposes allowed
- β Commercial use prohibited without explicit permission
- β Distribution outside academic context requires attribution
For questions, collaborations, or commercial licensing inquiries, please contact the authors or course instructors.
Project Repository: https://github.com/adriansotomora/mlops_group8
Experiment Tracking: Weights & Biases Project