MulaiMulai sekarang secara gratis

Which articles are similar to 'Cristiano Ronaldo'?

In the video, you learned how to use NMF features and the cosine similarity to find similar articles. Apply this to your NMF model for popular Wikipedia articles, by finding the articles most similar to the article about the footballer Cristiano Ronaldo. The NMF features you obtained earlier are available as nmf_features, while titles is a list of the article titles.

Latihan ini adalah bagian dari kursus

Unsupervised Learning in Python

Lihat Kursus

Petunjuk latihan

  • Import normalize from sklearn.preprocessing.
  • Apply the normalize() function to nmf_features. Store the result as norm_features.
  • Create a DataFrame df from norm_features, using titles as an index.
  • Use the .loc[] accessor of df to select the row of 'Cristiano Ronaldo'. Assign the result to article.
  • Apply the .dot() method of df to article to calculate the cosine similarity of every row with article.
  • Print the result of the .nlargest() method of similarities to display the most similar articles. This has been done for you, so hit 'Submit Answer' to see the result!

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Perform the necessary imports
import pandas as pd
from ____ import ____

# Normalize the NMF features: norm_features
norm_features = ____

# Create a DataFrame: df
df = ____

# Select the row corresponding to 'Cristiano Ronaldo': article
article = df.loc[____]

# Compute the dot products: similarities
similarities = ____

# Display those with the largest cosine similarity
print(similarities.nlargest())
Edit dan Jalankan Kode