Aan de slagGa gratis aan de slag

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!

Deze oefening maakt deel uit van de cursus

Unsupervised Learning in Python

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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 = ____
Code bewerken en uitvoeren