← Selected work

PYTHON · ENSEMBLE LEARNING · BEHAVIORAL SEGMENTATION

04

Song Cohorts & Marketing Ensemble

A repeatable analysis that groups songs by listening characteristics and ranks marketing candidates with supervised ensembles.

PYBehavior → Cohorts
Signals → Recommendations

A streaming provider has thousands of possible tracks to recommend and market. Popularity alone does not explain which songs feel related, which listener preferences they may fit, or which less-obvious tracks deserve testing. The business needs a repeatable way to transform audio attributes into understandable groups and prioritized candidates.

The project explores how behavior and audio characteristics can support better music discovery. Cohorts answer who a song may appeal to by identifying similar energy, danceability, acoustic character, mood, tempo, and live feel. Ensemble classification answers which songs should receive marketing attention first by estimating their association with higher popularity.

The notebook cleans 1,610 Spotify tracks, engineers interpretable features, standardizes the clustering space, uses PCA for visualization, compares K-Means solutions with silhouette scoring, and creates two explainable cohorts. A supervised pipeline then benchmarks Random Forest, Extra Trees, Gradient Boosting, AdaBoost, and soft voting using accuracy, precision, recall, F1, and ROC-AUC.

A simplified view of how information moves through the solution.

Technology choices were made around operating constraints, maintainability, integration boundaries, and the people using the system.

Language

Python

Python keeps data preparation, exploratory analysis, modeling, evaluation, and export in one readable workflow.

Data

pandas / NumPy

They provide reliable tabular cleaning, feature engineering, aggregation, and vectorized numerical operations for repeatable dataset processing.

Machine Learning

scikit-learn

Its composable preprocessing, PCA, clustering, ensemble, and metric APIs make model comparisons consistent and reduce leakage risk.

Visualization

Matplotlib / Seaborn

Visual EDA, correlation views, silhouette comparisons, and cohort plots make the modeling logic understandable to non-ML stakeholders.

Workflow

Jupyter

The notebook format combines executable analysis, outputs, assumptions, and business interpretation into one reviewable artifact.

Languages

Python

Frameworks

Jupyter

Databases

CSV dataset

Cloud

GitHub

Machine Learning

PCA · K-Means · Extra Trees · Soft Voting

AI

Behavioral ranking

APIs

Spotify-derived features

Deployment

Reusable notebook outputs

HARDEST CHALLENGE

The hardest challenge was combining an unsupervised business question—what songs belong together—with a supervised one—which songs deserve marketing priority—without confusing the purpose of either model.

HOW I SOLVED IT

I designed a two-layer workflow. Standardized audio features feed PCA and K-Means for interpretable cohorts; a separate preprocessing and ensemble pipeline predicts the high-popularity segment and compares models on multiple metrics.

LESSON LEARNED

A model should answer one clear decision question. Separating segmentation from prioritization made the results easier to explain and more reusable for future datasets.

Concise implementation patterns that show the engineering beneath the interface.

pythonSelecting the cohort count

The notebook compares multiple K-Means solutions instead of choosing a cluster count visually. The best silhouette score becomes the selected cohort count.

silhouette_results = []

for k in range(2, 11):
    model = KMeans(
        n_clusters=k,
        random_state=RANDOM_STATE,
        n_init=5,
        algorithm="lloyd"
    )
    labels = model.fit_predict(X_cluster_scaled)
    score = silhouette_score(
        X_cluster_scaled,
        labels,
        sample_size=500,
        random_state=RANDOM_STATE
    )
    silhouette_results.append({"k": k, "score": score})

best_k = max(silhouette_results, key=lambda item: item["score"])["k"]
pythonComparing diverse ensemble learners

Soft voting combines probability estimates from structurally different learners. The final selection still uses recorded ROC-AUC and F1 results rather than assuming the combined model must win.

voting_model = VotingClassifier(
    estimators=[
        ("rf", base_models["Random Forest"]),
        ("et", base_models["Extra Trees"]),
        ("gb", base_models["Gradient Boosting"]),
        ("ada", base_models["AdaBoost"])
    ],
    voting="soft",
    n_jobs=1
)

models = {
    **base_models,
    "Soft Voting Ensemble": voting_model
}

model_results = pd.DataFrame(results).sort_values(
    ["roc_auc", "f1"], ascending=False
)
  • Creates explainable music cohorts for recommendation and playlist testing.
  • Ranks marketing candidates using multiple model families instead of one heuristic.
  • Processes and validates 1,610 tracks through a repeatable workflow.
  • Selected two cohorts by comparing silhouette scores from k=2 through k=10.
  • Recorded 0.898 ROC-AUC for Extra Trees and 86.85% accuracy for soft voting.