모든 영화 쌍 찾기
이 연습에서는 같은 사람이 시청한 모든 영화 쌍, 즉 영화 쌍의 모든 순열을 찾는 방법을 실습해 봅니다.
user_ratings_df가 다시 로드되어 있으며, 사용자와 그들이 본 영화가 들어 있습니다.
먼저 리스트에 적용했을 때 가능한 모든 항목 쌍을 찾는 함수를 만들어야 합니다.
사용하기 편하도록, 이 값을 DataFrame으로 출력하세요.
같은 사람이 본 영화만 찾고 모든 가능한 순열을 찾는 것이 아니므로, 함수를 적용할 때 user_id로 그룹화합니다.
이 연습은 강의의 일부입니다
Python으로 추천 엔진 만들기
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
from itertools import permutations
# Create the function to find all permutations
def ____(x):
pairs = pd.____(list(____(x.values, 2)),
columns=['movie_a', 'movie_b'])
return pairs
# Apply the function to the title column and reset the index
movie_combinations = user_ratings_df.____('userId')['title'].____(find_movie_pairs)
print(movie_combinations)