'Cristiano Ronaldo'와 유사한 글은 무엇일까요?
영상에서 NMF 특성과 코사인 유사도를 사용해 유사한 글을 찾는 방법을 배웠습니다.
이제 이를 인기 있는 Wikipedia 글에 대한 NMF 모델에 적용해, 축구 선수 Cristiano Ronaldo에 관한 글과 가장 유사한 글을 찾아보세요. 앞서 구한 NMF 특성은 nmf_features에, 글 제목 목록은 titles에 저장되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 Unsupervised Learning
연습 안내
sklearn.preprocessing에서normalize를 가져오세요.normalize()함수를nmf_features에 적용하고 결과를norm_features로 저장하세요.titles를 인덱스로 사용해norm_features로부터 DataFramedf를 생성하세요.df의.loc[]접근자를 사용해'Cristiano Ronaldo'행을 선택하고, 결과를article에 할당하세요.df의.dot()메서드를article에 적용해 모든 행과article의 코사인 유사도를 계산하세요.- 가장 유사한 글을 표시하기 위해
similarities의.nlargest()결과를 출력하세요. 이 부분은 이미 준비되어 있으니 'Submit Answer'를 눌러 결과를 확인하세요!
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# 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())