Introduction
Hit prediction across Afrobeats and Amapiano begins as a data-integration problem, not a modeling problem. I built a multi-source dataset from 10 Spotify playlists, then joined Spotify metadata and audio attributes with TikTok virality, streaming velocity, and Billboard Africa presence. Because titles differed across every source, I created a fuzzy entity-resolution pipeline to reconcile featured artists, remixes, punctuation, and casing before modeling.
I modeled the genres separately and defined market-specific hit criteria rather than applying one Western pop threshold to both. The pipeline uses a fixed snapshot date, cached API responses, stratified cross-validation, and out-of-fold predictions so that the labels and evaluation remain reproducible.
Final Model Results
On 60 labeled tracks, 29 Afrobeats and 31 Amapiano, the class-weighted Random Forest (without the lyric-sentiment feature) achieved an Afrobeats hit-class F1 of 0.94 with 1.00 precision and 0.89 recall, and an Amapiano hit-class F1 of 0.91 with 1.00 precision and 0.83 recall.
In the initial held-out split, logistic regression reached 80% Amapiano accuracy while producing 0.00 hit recall, exposing the majority-class failure that accuracy concealed. I therefore selected models using minority-class precision, recall, and F1 rather than headline accuracy.
These results show a promising classification signal on a small, domain-defined dataset. They are not production forecasting estimates.
Read the Code
The Modeling Question
The hardest problem was defining the target, not fitting the model. Hit-prediction research is dominated by Western pop markets, where chart position, radio play, and streaming scale follow different patterns. Applying one universal threshold would systematically mislabel songs from two distinct ecosystems.
I therefore created separate rules by genre. An Afrobeats track required at least three of four signals: Spotify popularity of 73 or higher, TikTok virality, at least 300,000 streams per day, or Billboard Africa presence. An Amapiano track required all three of its market-adjusted signals: popularity of 65 or higher, TikTok virality, and at least 75,000 streams per day.
This choice made the project a test of domain modeling, data integration, and evaluation judgment rather than a generic application of an algorithm to Spotify features.
🔍 KEY ENGINEERING DECISIONS

Methodology
&
Insights
Methodology & Insights
1. Authenticated data collection
I built the Spotify ingestion layer with Spotipy and OAuth 2.0, storing credentials in environment variables. The pipeline paginated through 10 playlists in batches of 100 tracks, paused between requests to respect API limits, handled failures at the playlist level, and collected track IDs, artists, titles, popularity, and available audio metadata.
2. Multi-source entity resolution
The same song appeared differently across Spotify, streaming records, TikTok data, and Billboard Africa. Featured artists, remix labels, punctuation, casing, and alternate spellings prevented direct joins.
I normalized titles and combined token-sort fuzzy matching with string-similarity checks. Matches required an 80% similarity threshold before records were joined. This converted inconsistent source data into one analysis-ready table.
3. Genre-specific label design
I assigned hit labels separately for Afrobeats and Amapiano because their streaming scales and chart pathways differ. The Afrobeats rule used popularity, TikTok virality, streams per day, and Billboard Africa presence. The Amapiano rule used lower market-adjusted popularity and streaming thresholds and excluded Billboard Africa.
4. Reproducible feature construction
Streams per day depends on the date used in the denominator. I therefore replaced datetime.today() with a fixed snapshot date:
current_date = datetime(2025, 4, 15)
This ensures that streaming velocity and every derived label reproduce identically on future runs.
5. Imbalance-aware modeling
I trained logistic regression and Random Forest models separately by genre. Stratified 5-fold cross-validation preserved the limited proportion of hits in each fold, while cross_val_predict generated out-of-fold predictions for minority-class precision, recall, and F1.
The initial logistic-regression split produced 80% Amapiano accuracy but zero correctly detected hits. The class-weighted Random Forest corrected that failure and became the final base model.
Lyric Analysis: Genius + VADER
I extended the pipeline with a text feature by retrieving lyrics through the Genius API and scoring them with VADER. Results were cached to CSV so rerunning the notebook would not repeatedly call the API. Usable sentiment scores were retrieved for 44 of 60 tracks, with missing values filled using the within-genre median.
lyric_sentiment ranked third in Afrobeats feature importance at approximately 0.11, compared with approximately 0.05 for Amapiano. However, adding sentiment reduced Afrobeats hit-class F1 from the stronger base-model result to approximately 0.82, while Amapiano remained near 0.91. The NLP extension therefore remained an experiment rather than part of the selected final model.
Findings
The strongest feature importances exposed the model’s largest validity threat: target leakage.
Spotify popularity, streaming velocity, and TikTok virality directly contribute to the hit labels for both genres. Billboard Africa presence also contributes to the Afrobeats label. Their high importance therefore shows that the models learned the rule-based target, but it does not establish that those variables can forecast a future hit.
The audio-side result is narrower but more defensible. Tempo, duration, and beat-strength variables showed little separation at this sample size. The current experiment provides limited evidence that conventional musical structure alone distinguishes hits, but a leakage-free design is required before concluding that platform signals outperform audio characteristics.
The lyric-sentiment contrast must also be interpreted as a measurement warning. Sentiment importance was approximately 0.11 for Afrobeats and 0.05 for Amapiano, but VADER is English-trained and was not validated on the Zulu and Xhosa lyrics common in Amapiano. The weak Amapiano result is therefore more plausibly a language-coverage artifact than evidence that lyrics matter less in the genre.
Finally, the sample contains only 60 labeled tracks and 15 total hits. A one-song classification change can materially shift precision, recall, and F1. The reported metrics should be treated as promising signals from a reproducible prototype, not stable production estimates.
Reflection & Future Directions
The next experiment must predict future success using only information available near release.
I would redefine the target as an outcome observed after a forecasting window, such as future chart entry or streaming growth during days 30 through 60. Model inputs would be restricted to release-time audio characteristics, first-week TikTok velocity, early playlist exposure, artist history, and other signals available before the outcome occurs.
Popularity, mature streams per day, and any other variables used to determine the future label would be excluded. I expect performance to fall, but that lower score would answer the more valuable question: can the model identify a hit before it has already become one?
The lyric experiment also requires a measurement redesign. I would first detect lyric language, then evaluate a multilingual sentiment model with verified Nguni-language coverage against a manually annotated subset. That would distinguish a genuinely weak sentiment signal from a tool that cannot interpret the text.
Finally, I would expand the labeled dataset and introduce a temporal holdout. The model would train only on tracks available by the April 15, 2025 snapshot and be tested on songs released afterward. This would measure generalization across time rather than repeated classification within one historical sample.
The central insight is not that one algorithm can declare which song will succeed. It is that hit forecasting in Afrobeats and Amapiano requires market-aware labels, reliable cross-platform identity resolution, and a strict separation between early signals and outcomes.






