Training Track Affinity Model
Introduction: Why Predict Track Affinity?
Welcome back! In the previous lesson, you learned how to prepare training data from user session logs. Now, we are ready to take the next step: training a machine learning model that can predict which tracks a user is likely to enjoy. This is called predicting track affinity.
Track affinity is a measure of how much a user might like a particular track. By predicting this, we can recommend songs that users are more likely to enjoy, making the music player smarter and more personalized. In this lesson, you will learn how to train a simple but effective model to make these predictions.
Understanding the Training Data
Before training our model, let’s quickly review what kind of data we’re working with.
The function prepare_training_data() returns:
- A feature matrix
Xwhere each row is a combination of a user profile vector and a track embedding. A label vectory, where: 1means the user listened to (liked) the track0means the user did not listen to (negative sample) Each feature vector may look like this:
This structure is important: our model will try to learn a function like f(user, track) → probability of liking.
Why Logistic Regression?
In this project, we use logistic regression because our goal is a binary classification:
1→ The user is likely to enjoy the track (positive sample)0→ The user is unlikely to enjoy the track (negative sample)
Logistic regression is a simple yet effective model for this kind of task because:
- It predicts probabilities, not just yes/no outcomes. This is useful for ranking recommendations by likelihood.
- It’s interpretable — the learned weights show which features push predictions higher or lower.
- It’s fast to train and works well even with small datasets, making it ideal for an educational setting before moving on to more complex models.
- It outputs a sigmoid function result between 0 and 1, which maps naturally to the idea of “likelihood of liking.”
While real-world recommendation systems may use deep learning or more complex models, logistic regression is a great starting point to:
- Understand the full pipeline from data preparation to prediction.
- Build intuition for how features influence recommendations.
- Avoid overfitting when data is limited.
