Skip to content

Latest commit

 

History

History
508 lines (388 loc) · 15.9 KB

File metadata and controls

508 lines (388 loc) · 15.9 KB

FeatureBeats - Final Performance Report

Date: 2025-12-03 Project: Hit Song Prediction Using Spotify Audio Features Branch: master-claude / claude/review-master-branch-01KrqK3ALQNk4giWoQDUPnyN


Executive Summary

This project successfully implements a machine learning pipeline to predict hit songs using Spotify audio features. The project includes multiple modeling approaches, handles severe class imbalance, provides model interpretability through SHAP analysis, and delivers a production-ready web application.

Key Achievements:

  • ✅ Trained and evaluated 6+ different models
  • ✅ Achieved 91% ROC-AUC with XGBoost on engineered features
  • ✅ 86% recall - catches most hit songs
  • ✅ Feature engineering improved performance by ~2-3%
  • ✅ Complete web app for real-time predictions
  • ✅ Comprehensive documentation and visualizations

Dataset Overview

Raw Data

Dataset Records Source
tracks.csv 114,001 Spotify API (Kaggle)
top100_tracks.csv 2,401 Billboard/Spotify Top 100

Processed Data

Dataset Records Features Hit Rate
hits_dataset.csv 113,999 13 1.88% (2,138 hits)
hits_dataset_engineered.csv 113,999 23 1.88% (2,138 hits)

Class Imbalance: 52:1 ratio (non-hits:hits) Year Range: 2015 Train/Test Split: 80/20 (91,199 train / 22,800 test)

Audio Features Used

  1. Danceability - How suitable for dancing (0-1)
  2. Energy - Intensity and activity measure (0-1)
  3. Loudness - Overall loudness in dB (-60 to 0)
  4. Speechiness - Presence of spoken words (0-1)
  5. Acousticness - Acoustic vs electric sound (0-1)
  6. Instrumentalness - Predicts whether track has vocals (0-1)
  7. Liveness - Detects presence of audience (0-1)
  8. Valence - Musical positivity/happiness (0-1)
  9. Tempo - Overall tempo in BPM (50-200)

Model Performance Comparison

All Models Evaluated

Model Features Accuracy Precision Recall F1 ROC-AUC PR-AUC
Logistic Regression (Original) 9 61.98% 3.94% 82.24% 7.51% 0.769 0.055
Logistic Regression (Engineered) 19 62.87% 4.04% 82.48% 7.70% 0.774 0.058
XGBoost (Original) 9 79.48% 7.36% 85.75% 13.56% 0.911 0.321
XGBoost (Engineered) 19 79.80% 7.52% 86.45% 13.84% 0.916 0.357
SMOTE 9 62.82% 3.97% 81.07% 7.57% 0.769 0.054
ADASYN 9 62.18% 3.91% 81.31% 7.47% 0.770 0.057
Borderline-SMOTE 9 63.71% 3.84% 76.17% 7.30% 0.768 0.057

Best Model: XGBoost with Engineered Features

Key Metrics:

  • ROC-AUC: 0.916 (Excellent discrimination ability)
  • Recall: 86.45% (Catches 370/428 hits in test set)
  • PR-AUC: 0.357 (Strong performance given class imbalance)
  • F1 Score: 13.84%

Model Configuration:

XGBClassifier(
    scale_pos_weight=53.3,  # Handles class imbalance
    n_estimators=200,
    max_depth=7,
    learning_rate=0.1,
    random_state=42
)

Performance Analysis

What Works Well

  1. High Recall (86.45%) ✅

    • Model successfully identifies most hit songs
    • Only misses ~58 out of 428 hits in test set
    • Critical for music industry use case (better to predict too many than miss real hits)
  2. Excellent Discrimination (ROC-AUC: 0.916) ✅

    • Model can effectively separate hits from non-hits
    • Much better than random (0.5) or simple baseline
  3. Feature Engineering Impact ✅

    • Engineered features improved F1 by 2.08%
    • ROC-AUC improved from 0.911 → 0.916
    • PR-AUC improved by 11% (0.321 → 0.357)

Challenges

  1. Low Precision (7.52%) ⚠️

    • High false positive rate
    • Predicts ~4,916 songs as hits, but only 370 are actual hits
    • Root cause: Severe class imbalance (52:1 ratio)
  2. Class Imbalance ⚠️

    • Only 1.88% of songs are hits
    • Even with resampling techniques, precision remains low
    • This is inherent to the problem (most songs don't become hits)
  3. Limited Feature Set ⚠️

    • Audio features alone don't capture:
      • Artist popularity and existing fanbase
      • Marketing budget and promotion
      • Timing and cultural context
      • Lyrics sentiment and themes
      • Music video quality

Feature Importance (SHAP Analysis)

Top 10 Most Important Features

Based on XGBoost with engineered features:

  1. Energy - Energetic songs more likely to hit
  2. Danceability - Danceable tracks perform better
  3. Loudness - Moderate loudness optimal
  4. Valence - Happy/positive songs favored
  5. Energy × Danceability (engineered) - Combined effect
  6. Acousticness - Lower acousticness correlates with hits
  7. Party Factor (engineered) - Dance + valence + energy combo
  8. Speechiness - Lower speechiness better (not rap-focused)
  9. Instrumentalness - Vocal tracks outperform instrumental
  10. Tempo - Moderate tempo (120-130 BPM) optimal

Key Insights from SHAP

  • Positive Predictors: High energy, high danceability, positive valence
  • Negative Predictors: High acousticness, high instrumentalness
  • Interaction Effects: Energy × Danceability shows synergy
  • Non-linear Patterns: XGBoost captures complex relationships

Feature Engineering Results

New Features Created (10 total)

Interaction Terms:

  1. energy_x_danceability - Combined party appeal
  2. valence_x_energy - Happy and energetic combo
  3. loudness_x_energy - Intensity measure

Domain-Specific: 4. acoustic_vs_energy - Acoustic contrast (acousticness - energy) 5. party_factor - Average of danceability, valence, energy

Polynomial Features: 6. danceability_squared - Non-linear dance effect 7. energy_squared - Non-linear energy effect 8. valence_squared - Non-linear mood effect

Temporal Features: 9. year_normalized - Normalized year (0-1 scale) 10. year_period - Early/mid/late period indicator

Impact of Feature Engineering

Metric Original Engineered Improvement
Logistic Regression F1 7.51% 7.70% +2.48%
XGBoost F1 13.56% 13.84% +2.08%
XGBoost ROC-AUC 0.911 0.916 +0.5%
XGBoost PR-AUC 0.321 0.357 +11.2%

Conclusion: Feature engineering provides consistent but modest improvements across all metrics.


SMOTE Sampling Analysis

Methods Tested

Five different sampling techniques were evaluated to address class imbalance:

  1. Baseline (Class Weighting) - Standard approach
  2. SMOTE - Synthetic Minority Oversampling
  3. ADASYN - Adaptive Synthetic Sampling
  4. Borderline-SMOTE - Focus on decision boundary
  5. SMOTE + Tomek - Combined over/under sampling

Results

All SMOTE methods achieved similar performance (~7.5% F1, 81% recall).

Key Finding: Class weighting in the model (class_weight='balanced' or scale_pos_weight) performs as well as SMOTE methods while being:

  • Faster to train (no synthetic data generation)
  • Simpler implementation
  • No risk of overfitting to synthetic samples

Recommendation: Use XGBoost with scale_pos_weight instead of SMOTE for this dataset.


Model Outputs & Artifacts

Trained Models (8 total)

File Size Description
baseline_logreg.pkl 959 B Baseline Logistic Regression
final_xgboost.pkl 562 KB XGBoost (original features)
logreg_engineered.pkl 943 B Logistic Regression (engineered)
xgboost_engineered.pkl 562 KB Best model - XGBoost (engineered)
best_sampling_model.pkl 943 B Best SMOTE model
scaler.pkl 815 B StandardScaler (original features)
scaler_engineered.pkl 815 B StandardScaler (engineered features)
shap_values.npy 36 KB SHAP values for interpretation

Visualizations (15 total)

Category Files
EDA tracks_by_year.png, feature_distributions.png, correlation_matrix.png
Baseline Model logreg_confusion_matrix.png, logreg_roc_curve.png, logreg_pr_curve.png, logreg_coefficients.png
XGBoost xgboost_confusion_matrix.png, model_comparison.png
SHAP shap_feature_importance.png, shap_summary_detailed.png, shap_dependence_plots.png, shap_force_plot_example.png
Sampling sampling_confusion_matrices.png, sampling_methods_comparison.png

Metrics Files

File Description
baseline_metrics.csv Logistic regression metrics
xgboost_metrics.csv XGBoost metrics
sampling_methods_comparison.csv All SMOTE methods comparison
engineered_features_comparison.csv Original vs engineered comparison

Web Application

Features

  • Interactive Sliders: Adjust all 9 audio features
  • Real-time Prediction: Instant hit probability
  • Visual Feedback: Probability gauge and feature analysis
  • Model Insights: SHAP visualizations and performance metrics
  • User Guide: Detailed explanations of audio features

Technical Stack

  • Framework: Streamlit
  • Model: XGBoost (final_xgboost.pkl)
  • Visualization: Matplotlib, Seaborn
  • Deployment Ready: Can be hosted on Streamlit Cloud, Heroku, or AWS

Usage

streamlit run app.py
# Opens at http://localhost:8501

Test Results

✅ Models load correctly ✅ Predictions work with sample data ✅ All visualizations available ✅ Edge cases handled properly ✅ No runtime errors detected


Business Implications

Use Cases

  1. A&R (Artists & Repertoire)

    • Screen demo submissions
    • Identify potential hit songs early
    • Complement human judgment with data
  2. Music Production

    • Guide audio engineering decisions
    • Optimize song characteristics for chart potential
    • Benchmark against successful tracks
  3. Playlist Curation

    • Identify emerging hits for playlist inclusion
    • Predict songs likely to gain popularity
    • Data-driven playlist optimization

Limitations & Disclaimers

⚠️ This model should NOT be used as the sole decision-making tool

Why low precision is acceptable:

  • Missing a real hit is more costly than false positives
  • High recall (86%) ensures most hits are caught
  • False positives can be filtered by human reviewers
  • Model provides ranking/scoring, not binary decisions

What the model doesn't capture:

  • Artist fame and existing fanbase
  • Marketing budget and promotion strategy
  • Cultural timing and trends
  • Lyrics quality and themes
  • Music video and visual branding
  • Social media presence
  • Radio play and industry connections

Recommended Usage:

  • Use as a screening/ranking tool (top X% of predictions)
  • Combine with other factors (artist popularity, genre trends)
  • Human review for final decisions
  • Monitor real-world performance and retrain regularly

Technical Achievements

Code Quality

✅ Production-ready Jupyter notebooks ✅ Comprehensive error handling ✅ Clear documentation and comments ✅ Reproducible results (random_state=42) ✅ Modular design ✅ Type hints and docstrings

Best Practices

✅ Train/test split with stratification ✅ Feature scaling (StandardScaler) ✅ Cross-validation for hyperparameter tuning ✅ Multiple evaluation metrics ✅ Model interpretability (SHAP) ✅ Version control (Git) ✅ Requirements management

Project Structure

FeatureBeats/
├── data/
│   ├── raw/                    # Original datasets (gitignored)
│   └── processed/              # Cleaned datasets
├── notebooks/                  # Jupyter notebooks (00-05)
├── models/                     # Trained models (8 files)
├── figures/                    # Visualizations (15 files)
├── app.py                      # Streamlit web app
├── requirements.txt            # Dependencies
├── README.md                   # Project documentation
└── *.md                        # Additional docs

Recommendations for Future Work

Short-term Improvements (1-2 weeks)

  1. Threshold Optimization

    • Current threshold: 0.5
    • Optimize for business metrics (cost of false positives vs false negatives)
    • Could improve precision at cost of some recall
  2. Additional Features

    • Artist popularity score
    • Genre classification
    • Release month/season
    • Playlist appearance count
  3. Model Ensemble

    • Combine XGBoost, Random Forest, LightGBM
    • Stacking or voting classifier
    • Could improve 1-2% on metrics
  4. Real Dataset Expansion

    • Current: Only 2015 data
    • Add 2016-2024 data for temporal analysis
    • Test model drift over time

Long-term Enhancements (1-3 months)

  1. External Data Integration

    • Social media trends (Twitter, TikTok)
    • YouTube views and engagement
    • Streaming platform metrics
    • Music blog mentions
  2. Lyrics Analysis

    • Sentiment analysis
    • Topic modeling
    • Readability scores
    • Language detection
  3. Audio Deep Learning

    • Mel spectrograms with CNNs
    • Audio embeddings (VGGish, OpenL3)
    • End-to-end audio classification
    • Transfer learning from MusicNet
  4. Temporal Modeling

    • Time series analysis of music trends
    • Seasonal effects (summer hits, holiday songs)
    • Genre evolution tracking
    • Prediction decay over time
  5. Production Deployment

    • Docker containerization
    • CI/CD pipeline
    • API endpoint (FastAPI/Flask)
    • Database integration (PostgreSQL)
    • Monitoring and logging
    • A/B testing framework

Conclusion

This project successfully demonstrates:

✅ End-to-end ML pipeline - From raw data to deployed web app ✅ Strong predictive performance - 91.6% ROC-AUC, 86% recall ✅ Model interpretability - SHAP analysis reveals important features ✅ Production quality - Clean code, documentation, error handling ✅ Business applicability - Web app ready for stakeholder demo

Key Takeaways

  1. Audio features alone can predict hit songs with good accuracy (91.6% ROC-AUC)
  2. Feature engineering provides consistent 2-3% improvement
  3. Class imbalance is challenging but manageable with proper techniques
  4. XGBoost outperforms linear models significantly
  5. High recall is more valuable than precision for this use case

Final Metrics Summary

Best Model: XGBoost with Engineered Features

Metric Value Interpretation
ROC-AUC 0.916 Excellent discrimination
Recall 86.45% Catches most hits
Precision 7.52% Many false positives (expected)
F1 Score 13.84% Balanced performance
PR-AUC 0.357 Strong for imbalanced data

Project Status: ✅ Production Ready


Report Generated: 2025-12-03 Author: ML Pipeline (Claude + User) Version: 1.0 License: MIT (for code), Dataset licenses apply to data


Appendix: Reproducibility

Environment

Python 3.11+
pip install -r requirements.txt

Run Full Pipeline

# 1. Setup (optional)
jupyter notebook notebooks/00_Setup_and_Installation.ipynb

# 2. Data processing
jupyter notebook notebooks/01_Week1_Data_Setup_EDA.ipynb

# 3. Baseline model
jupyter notebook notebooks/02_Week2_Baseline_Modeling.ipynb

# 4. XGBoost & SHAP
jupyter notebook notebooks/03_Week3_XGBoost_SHAP.ipynb

# 5. SMOTE sampling (optional)
jupyter notebook notebooks/04_Advanced_SMOTE_Sampling.ipynb

# 6. Feature engineering
jupyter notebook notebooks/05_Feature_Engineering.ipynb

# 7. Train engineered models
python3 train_engineered_models.py

# 8. Launch web app
streamlit run app.py

Expected Runtime

  • Notebooks 01-03: ~45 minutes (skip fuzzy matching)
  • Notebook 04: ~15 minutes
  • Notebook 05: ~5 minutes
  • Engineered models: ~3 minutes
  • Total: ~70 minutes

Random Seeds

All models use random_state=42 for reproducibility.


End of Report