PYTHON · ENSEMBLE LEARNING · BEHAVIORAL SEGMENTATION
04Song Cohorts & Marketing Ensemble
A repeatable analysis that groups songs by listening characteristics and ranks marketing candidates with supervised ensembles.
Signals → Recommendations
Business Problem
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.
Why I Built It
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.
Solution
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.
Architecture
A simplified view of how information moves through the solution.
Why These Technologies?
Technology choices were made around operating constraints, maintainability, integration boundaries, and the people using the system.
Python
Python keeps data preparation, exploratory analysis, modeling, evaluation, and export in one readable workflow.
pandas / NumPy
They provide reliable tabular cleaning, feature engineering, aggregation, and vectorized numerical operations for repeatable dataset processing.
scikit-learn
Its composable preprocessing, PCA, clustering, ensemble, and metric APIs make model comparisons consistent and reduce leakage risk.
Matplotlib / Seaborn
Visual EDA, correlation views, silhouette comparisons, and cohort plots make the modeling logic understandable to non-ML stakeholders.
Jupyter
The notebook format combines executable analysis, outputs, assumptions, and business interpretation into one reviewable artifact.
Technical Highlights
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
Challenges Solved
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.
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.
A model should answer one clear decision question. Separating segmentation from prioritization made the results easier to explain and more reusable for future datasets.
Engineering Spotlight
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
)Business Impact
- 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.