Skip to content

FaNa-AI/LSTM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

🎵 Spotify Song Popularity Prediction with LSTM

A PyTorch-based deep learning project that predicts the popularity of songs on Spotify using their audio features. It utilizes an LSTM model to perform regression on sequential-like data (although each song is treated as a sequence of one).


📁 Dataset

  • Input file: spotify_songs.csv

  • Features used:

    • danceability, energy, loudness, speechiness, acousticness, instrumentalness, liveness, valence, tempo
  • Target: track_popularity


⚙️ Pipeline Overview

1️⃣ Data Preprocessing

  • Drop rows with missing values
  • Normalize features using StandardScaler
  • Split data into train/test sets
  • Convert data into PyTorch tensors

2️⃣ Model: LSTM

A custom LSTM regression model:

Input Size: 9
Hidden Size: 64
Layers: 1
Output: 1 (popularity score)

3️⃣ Training

  • Loss function: MSELoss
  • Optimizer: Adam (lr=0.001)
  • Epochs: 15
  • Batch size: 64

4️⃣ Evaluation

  • Mean Squared Error (MSE) on the test set
  • Line plot of training loss over epochs

📈 Sample Output

Epoch 1/15, Loss: 152.3496
...
Epoch 15/15, Loss: 43.7221

Test MSE Loss: 38.9315

🖼️ Training Loss Visualization

A plot is generated showing loss vs epochs:

loss-plot

You can use plt.savefig("training_loss.png") to save the figure locally.


▶️ How to Run

  1. ✅ Install dependencies:
pip install torch pandas numpy scikit-learn matplotlib
  1. 📂 Make sure spotify_songs.csv is in the same directory.

  2. 🚀 Run the script:

python your_script_name.py

📌 Notes

  • Designed for educational purposes to demonstrate regression with LSTMs.
  • Extendable to deeper networks or sequence data if needed.
  • Lightweight and easy to customize.

About

a simple PyTorch project that predicts the popularity score of songs using Spotify audio features and an LSTM regression model.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors