--- license: mit task_categories: - tabular-classification language: - en tags: - music - spotify - audio-features - eda - popularity - hit-prediction size_categories: - 10K **Assignment #1 โ€” EDA & Dataset | March 2026** --- ## ๐Ÿ“ฝ๏ธ Video Presentation --- ## ๐Ÿ“Œ Overview This project explores the **30,000 Spotify Songs** dataset to answer one core question: > **How do audio features โ€” danceability, energy, loudness, speechiness, tempo, acousticness, instrumentalness, liveness, valence, and duration โ€” affect the popularity of a song?** The goal is to identify the optimal range of audio features that music producers should aim for to increase the chances of their song becoming a hit. --- ## ๐Ÿ“‚ Dataset | Property | Details | |---|---| | **Source** | [Kaggle โ€” 30000 Spotify Songs](https://www.kaggle.com/datasets/joebeachcapital/30000-spotify-songs) | | **Raw Size** | 32,833 rows ร— 23 features | | **Final Size** | 32,790 rows ร— 25 features (after cleaning, feature engineering & column pruning) | | **Target Variable** | `track_popularity` (0โ€“100) | | **Hit Definition** | `track_popularity > 75` (top ~8.1% of all tracks) | ### Audio Features Explained | Feature | What It Means | Example | |---|---|---| | `danceability` | How easy it is to dance to (0.0โ€“1.0) | Low = slow ballad, High = club banger | | `energy` | Perceptual intensity and activity (0.0โ€“1.0) | Death metal = high, Bach prelude = low | | `loudness` | Average loudness in decibels (dB) | Closer to 0 = louder, โˆ’60 = almost silent | | `speechiness` | Presence of spoken words (0.0โ€“1.0) | >0.66 = mostly speech, <0.33 = music | | `acousticness` | Confidence that a track is acoustic (0.0โ€“1.0) | Guitar unplugged = high, EDM synths = low | | `instrumentalness` | Likelihood the track has no vocals (0.0โ€“1.0) | Jazz instrumental = high, pop singer = low | | `liveness` | Presence of a live audience (0.0โ€“1.0) | >0.8 = likely live recording | | `valence` | Musical positiveness (0.0โ€“1.0) | Happy/cheerful = high, sad/angry = low | | `tempo` | Estimated tempo in BPM | 60 BPM = slow, 180 BPM = very fast | | `duration_min` | Song length in minutes | 2 min = short, 6 min = long | --- ## ๐Ÿ› ๏ธ Setup ```python from google.colab import drive import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns ``` Developed in **Google Colab** with the dataset loaded from Google Drive. --- ## ๐Ÿงน Data Cleaning **Missing Values:** Found 5 rows with missing `track_name`, `track_artist`, and `track_album_name` โ€” all removed. **Duplicates:** None found โ€” no action needed. **Impossible Values:** - `tempo = 0 BPM` โ†’ dropped (1 track). A song with 0 BPM cannot exist. - `loudness > 0 dB` โ†’ dropped (6 tracks). Industry standard caps loudness at 0 dB. **Final shape after cleaning: (32,790, 23)** --- ## โš™๏ธ Feature Engineering Three new features were created: - **`release_year`** โ€” extracted from `track_album_release_date` (covers 1957โ€“2020) - **`is_hit`** โ€” `True` if `track_popularity > 75` (top ~8.1% of tracks by popularity score) - **`loudness_scaled`** โ€” loudness rescaled from dB (โˆ’60 to 0) to a 0โ€“100 range for readability - **`duration_min`** โ€” changed duration ms to duration in min. ## ๐Ÿ—‘๏ธ Column Pruning Two columns were intentionally dropped after feature engineering: - **`track_album_release_date`** โ€” used only to derive `release_year`. Once extracted, the original date string is redundant. - **`playlist_subgenre`** โ€” all genre analysis operates at the broad `playlist_genre` level. This column was never computed, visualized, or referenced. **Final dataset shape: (32,790, 25)** --- ## ๐Ÿ“Š Visualizations & Key Findings ### 1. Outlier Detection โ€” All 10 Audio Features ![Outlier Detection](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/OUTLIERS.png) Box plots across all 10 features reveal the spread and outliers in the dataset. Key observations: - **Tempo** clusters tightly between 100โ€“130 BPM - **Instrumentalness** is nearly flat near 0 โ€” ~90% of tracks have vocals - **Speechiness & Liveness** are heavily right-skewed โ€” most tracks are studio recordings with minimal spoken word - **Valence** is evenly spread, reflecting a healthy mix of happy and sad music All outliers were **kept** โ€” extreme values (e.g. 10-min songs, instrumental tracks) are valid artistic choices, not data errors. --- ### 2. Hit Rate Threshold Sensitivity ![Hit Rate Threshold](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/HIT_RATE_THRESH.png) To define "hit" objectively, every threshold from 60 to 85 was tested. Results: | Threshold | Hit Rate | Decision | |---|---|---| | 60 | 27.2% | Too generous โ€” over a quarter of songs can't all be hits | | 65 | 20.1% | Still too broad | | 70 | 13.5% | Getting closer | | **75** | **8.1%** | โœ… Selected โ€” meaningful minority, large enough to analyze | | 80 | 4.1% | Too strict โ€” loses too much signal | | 85 | 1.9% | Only mega-hits qualify | **Threshold = 75** was selected as the sweet spot. --- ### 3. Popularity Distribution & Hit/Non-Hit Split ![Popularity Distribution](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/HIT_THRESH_VALID.png) The popularity distribution shows a natural drop-off above 70, confirming that 75 sits right at the edge of the top tier. Result: **2,657 hits (8.1%)** vs **30,133 non-hits (91.9%)**. For every 1 hit, there are ~11 non-hit songs. --- ### 4. Hits vs Non-Hits โ€” Median Feature Comparison ![Median Comparison](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/MEDIAN_COMP.png) All 10 features normalized to 0โ€“1 and compared between hits and non-hits: - **โ†‘ Danceability** โ€” hits score consistently higher. Groove matters. - **โ†‘ Loudness** โ€” hits are louder. Tight mastering is industry standard. - **โ†‘ Acousticness** โ€” hits have a slightly more organic sound. - **โ†‘ Valence** โ€” hits trend happier. Feel-good music has a streaming edge. - **โ†“ Speechiness** โ€” hits are more melodic, less spoken-word. - **โ†“ Instrumentalness** โ€” hits almost always have vocals. - **โ†“ Liveness** โ€” hits are studio recordings, not live performances. - **โ†“ Tempo** โ€” hits are slightly slower (~118 BPM vs ~122 BPM average). - **โ†“ Duration** โ€” hits are shorter. Streaming rewards conciseness. - **~ Energy** โ€” similar between groups; hits are slightly lower in energy. --- ### 5. Correlation Heatmap โ€” All Audio Features ![Correlation Heatmap](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/HEATMAP.png) Key relationships revealed by the heatmap: - **Energy โ†” Loudness (`r = +0.68`)** โ€” the strongest link. Louder songs almost always feel more energetic. - **Energy โ†” Acousticness (`r = โˆ’0.54`)** โ€” acoustic tracks feel calmer and less intense. - **Loudness โ†” Acousticness (`r = โˆ’0.36`)** โ€” louder songs are less acoustic. - **Danceability โ†” Valence (`r = +0.33`)** โ€” happier songs tend to be more danceable. - **Instrumentalness โ†” Popularity (`r = โˆ’0.15`)** โ€” the clearest predictor: vocals = popularity. - **Duration โ†” Popularity (`r = โˆ’0.14`)** โ€” shorter songs perform better. All other features vs popularity show correlations below 0.10 โ€” no single feature is a magic predictor on its own. --- ### 6. Audio Features vs Track Popularity โ€” Scatter Plots ![Scatter Plots](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/SCATER.png) Each feature plotted against popularity with a linear trend line (`r` values shown): - **Instrumentalness (`r = โˆ’0.15`)** and **Duration (`r = โˆ’0.14`)** show the clearest negative trends. - **Acousticness (`r = +0.09`)** is the strongest positive predictor โ€” a touch of organic sound helps. - **Tempo (`r โ‰ˆ 0.00`)** is essentially flat โ€” tempo alone does not drive popularity. - **Energy, Speechiness, Liveness, Valence** all show weak but directionally consistent trends. --- ### 7. Music Trends Over Time ![Music Trends Over Time](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/TIME.png) Hit rates peaked in the mid-1960s (~17%) and surged again post-2015, reaching ~14% by 2019. **Why recent songs score higher:** Spotify's popularity score is recency-weighted โ€” it favors tracks with recent, high-volume streaming activity over all-time totals. Combined with the viral amplification of social media (TikTok, Instagram Reels), newer songs accumulate streams far faster than songs from previous decades could. This is a measurement artifact, not evidence that modern music is objectively better. --- ### 8. Songs count per year. ![Music Trends Over Time](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/track_count_per_year.png) Clearly shows a difference in amount of data per each year. ### 9. Hit Ratio by Genre ![Hit Ratio by Genre](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/GENERE.png) | Genre | Hit Ratio | Notes | |---|---|---| | **Pop** | **0.157** | Nearly double the overall average โ€” designed for mass appeal | | **Latin** | **0.138** | Strong global wave (Bad Bunny, J Balvin) shows in the data | | **R&B** | 0.098 | Above average โ€” loyal streaming audience | | **Rap** | 0.060 | Below average | | **EDM** | 0.044 | Lowest โ€” EDM success lives in festivals, not Spotify streams | --- ### 10. Sweet Spot by Genre โ€” KDE Analysis ![Sweet Spot by Genre](https://huggingface.co/datasets/Noam12345/my_first_asignment_ds/resolve/main/PHOTOS_NEW/SWEET_SPOT.png) KDE plots showing where hit songs cluster for **Pop, Latin, and R&B** across all 10 features: **Universal across all genres:** - High energy (0.6โ€“0.8), high loudness, near-zero instrumentalness and speechiness, low liveness, short duration (3โ€“4 min) **Genre-specific differences:** - **Tempo:** Pop/R&B peak at 95โ€“125 BPM; Latin shows a second peak at ~175 BPM (reggaeton) - **Danceability:** Latin requires the highest (~0.78), R&B allows more variation - **Valence:** Pop and Latin lean happier; R&B spans a wider emotional range - **Acousticness:** R&B allows more organic elements than Pop ## โœ… Summary & Conclusions #### General range for popular music | Feature | Direction | Hit Sweet Spot | |---|---|---| | Danceability | โ†‘ positive | 0.70โ€“0.85 | | Energy | ~ neutral | 0.60โ€“0.80 | | Loudness | โ†‘ positive | 85โ€“90 (scaled) | | Speechiness | โ†“ negative | < 0.10 | | Tempo | ~ irrelevant | Genre-dependent | | Acousticness | โ†‘ slight positive | Slightly above average | | Instrumentalness | โ†“ strong negative | ~0.0 (vocals essential) | | Liveness | โ†“ negative | < 0.15 (studio only) | | Valence | โ†‘ slight positive | Slightly above average | | Duration | โ†“ negative | 3โ€“4 minutes | ### Genre Sweet Spot Tables โ€” Producer Cheat Sheet Based on the KDE analysis of hit songs in each of the top 3 genres, here are the optimal feature ranges: #### ๐ŸŽค Pop | Feature | Sweet Spot | Notes | |---|---|---| | Danceability | 0.65โ€“0.80 | High but not extreme โ€” steady groove | | Energy | 0.60โ€“0.85 | Energetic, radio-ready feel | | Loudness (scaled) | 85โ€“90 | Loud, compressed mastering | | Speechiness | < 0.10 | Melody-first โ€” minimal spoken word | | Tempo | 95โ€“130 BPM | Standard pop range | | Acousticness | 0.05โ€“0.25 | Mostly produced, slight organic touch | | Instrumentalness | ~0.00 | Vocals are essential | | Liveness | < 0.15 | Studio production only | | Valence | 0.40โ€“0.75 | Leans happy and upbeat | | Duration | 3.0โ€“3.8 min | Short, replayable tracks | #### ๐Ÿ’ƒ Latin | Feature | Sweet Spot | Notes | |---|---|---| | Danceability | 0.75โ€“0.85 | Highest of all genres โ€” dance is mandatory | | Energy | 0.60โ€“0.85 | High energy, rhythm-driven | | Loudness (scaled) | 85โ€“90 | Same loud standard as pop | | Speechiness | < 0.10 | Singing over speaking | | Tempo | 95โ€“105 *or* 170โ€“200 BPM | Bimodal โ€” slow reggaeton *and* fast salsa/cumbia | | Acousticness | 0.10โ€“0.35 | Slightly more organic than pop | | Instrumentalness | ~0.00 | Always vocal | | Liveness | < 0.15 | Studio recordings dominate | | Valence | 0.50โ€“0.80 | Happy, feel-good energy | | Duration | 3.0โ€“4.0 min | Streaming-friendly length | #### ๐ŸŽถ R&B | Feature | Sweet Spot | Notes | |---|---|---| | Danceability | 0.60โ€“0.80 | Wider range โ€” groove matters but isn't everything | | Energy | 0.50โ€“0.75 | Slightly lower โ€” allows smooth, mellow tracks | | Loudness (scaled) | 80โ€“90 | A touch softer than pop/Latin | | Speechiness | < 0.15 | Slightly higher tolerance (rap-influenced R&B) | | Tempo | 95โ€“125 BPM | No second peak โ€” steady mid-tempo | | Acousticness | 0.10โ€“0.45 | Most acoustic-friendly genre โ€” organic sound welcome | | Instrumentalness | ~0.00 | Vocals remain essential | | Liveness | < 0.15 | Studio quality standard | | Valence | 0.25โ€“0.70 | Widest emotional range โ€” moody and happy both work | | Duration | 3.0โ€“4.2 min | Slightly longer than pop is acceptable | > **Bottom line:** High energy, loud mastering, vocals, and 3โ€“4 minutes are universal. The real genre fingerprint lives in **tempo** (Latin's bimodal peaks), **danceability** (Latin demands the most), **acousticness** (R&B allows the most), and **valence** (R&B allows the darkest mood). --- --- ## ๐Ÿ‘ค Author **Noam Fuchs** โ€” Data Science Assignment #1, March 2026