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
Exercise instructions
- Import:
NMF
fromsklearn.decomposition
.Normalizer
andMaxAbsScaler
fromsklearn.preprocessing
.make_pipeline
fromsklearn.pipeline
.
- Create an instance of
MaxAbsScaler
calledscaler
. - Create an
NMF
instance with20
components callednmf
. - Create an instance of
Normalizer
callednormalizer
. - Create a pipeline called
pipeline
that chains togetherscaler
,nmf
, andnormalizer
. - Apply the
.fit_transform()
method ofpipeline
toartists
. Assign the result tonorm_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 = ____