Get startedGet started for free

Recommend musical artists part I

In this exercise and the next, you'll use what you've learned about NMF to recommend popular music artists! You are given a sparse array artists whose rows correspond to artists and whose columns correspond to users. The entries give the number of times each artist was listened to by each user.

In this exercise, build a pipeline and transform the array into normalized NMF features. The first step in the pipeline, MaxAbsScaler, transforms the data so that all users have the same influence on the model, regardless of how many different artists they've listened to. In the next exercise, you'll use the resulting normalized NMF features for recommendation!

This exercise is part of the course

Unsupervised Learning in Python

View Course

Exercise instructions

  • Import:
    • NMF from sklearn.decomposition.
    • Normalizer and MaxAbsScaler from sklearn.preprocessing.
    • make_pipeline from sklearn.pipeline.
  • Create an instance of MaxAbsScaler called scaler.
  • Create an NMF instance with 20 components called nmf.
  • Create an instance of Normalizer called normalizer.
  • Create a pipeline called pipeline that chains together scaler, nmf, and normalizer.
  • Apply the .fit_transform() method of pipeline to artists. Assign the result to norm_features.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Perform the necessary imports
from ____ import ____
from ____ import ____, ____
from ____ import ____

# Create a MaxAbsScaler: scaler
scaler = ____

# Create an NMF model: nmf
nmf = ____

# Create a Normalizer: normalizer
normalizer = ____

# Create a pipeline: pipeline
pipeline = ____

# Apply fit_transform to artists: norm_features
norm_features = ____
Edit and Run Code