Skip to content
/ RNN Public

predicts Spotify song popularity using audio features and a simple RNN regression model in PyTorch.

Notifications You must be signed in to change notification settings

FaNa-AI/RNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

🎡 RNN-Based Spotify Song Popularity Prediction

This repository contains an implementation of a Recurrent Neural Network (RNN) using PyTorch to predict the popularity of songs on Spotify based on their audio features.

πŸ“Œ Overview

The goal of this project is to predict the track_popularity score of a song (on a scale from 0 to 100) using various musical and audio features such as danceability, energy, loudness, etc.

This implementation uses a simple RNN model for regression.

πŸ” Features Used

The model uses the following numerical features from the dataset:

  • danceability
  • energy
  • loudness
  • speechiness
  • acousticness
  • instrumentalness
  • liveness
  • valence
  • tempo

Target variable:

  • track_popularity

πŸ“ Dataset

The dataset file should be named spotify_songs.csv. Make sure to update the path in the script if needed:

df = pd.read_csv(r'c:\faezeh\MachineLearning\ForthPractice\rnn\rnn/spotify_songs.csv')

Missing data is dropped before training.

βš™οΈ Requirements

  • Python 3.8+
  • PyTorch
  • pandas
  • numpy
  • scikit-learn
  • matplotlib

Install the dependencies with:

pip install torch pandas numpy scikit-learn matplotlib

πŸ— Model Architecture

  • Input: (Batch, Sequence Length = 1, Features)

  • RNN Layer:

    • input_size = 9 (number of features)
    • hidden_size = 64
    • num_layers = 1
  • Fully Connected Output Layer: Maps the RNN output to a single regression value (song popularity).

🧠 Training

  • Optimizer: Adam
  • Loss Function: Mean Squared Error (MSE)
  • Epochs: 15
  • Batch Size: 64

Training loss is printed per epoch and also plotted at the end.

πŸ“ˆ Evaluation

After training, the model is evaluated on the test set and the final MSE loss is printed.

The training loss over epochs is visualized using a simple line plot.

πŸ“Š Output Example

Training Loss Plot

(Use plt.savefig("example_loss_plot.png") in the script if you'd like to save the plot.)

πŸ“‚ File Structure

β”œβ”€β”€ spotify_songs.csv       # Dataset
β”œβ”€β”€ rnn_regression.py       # Main script (your code)
└── README.md               # Project documentation

▢️ How to Run

python rnn_regression.py

About

predicts Spotify song popularity using audio features and a simple RNN regression model in PyTorch.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published