शुरू करेंमुफ़्त में शुरू करें

Recommender फंक्शन

इस अभ्यास में, आप लेसन और पिछले अभ्यास में चर्चा किए गए get_recommendations() नाम के एक recommender फंक्शन का निर्माण करेंगे। जैसा कि आप जानते हैं, यह एक title, cosine similarity मैट्रिक्स, और मूवी title व index मैपिंग को आर्ग्युमेंट्स के रूप में लेता है, और मूल title से सबसे समान 10 titles (खुद उस title को छोड़कर) की सूची आउटपुट करता है।

आपको metadata नाम का एक डेटासेट दिया गया है जिसमें मूवी titles और overviews शामिल हैं। इस डेटासेट का head कंसोल पर प्रिंट किया गया है।

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में NLP के लिए Feature Engineering

पाठ्यक्रम देखें

अभ्यास निर्देश

  • indices की title कुंजी का उपयोग करके उस मूवी का index प्राप्त करें जो दिए गए title से मेल खाती है।
  • sim_scores में से दस सबसे समान मूवीज़ निकालें और उन्हें वापस sim_scores में ही स्टोर करें।

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Generate mapping between titles and index
indices = pd.Series(metadata.index, index=metadata['title']).drop_duplicates()

def get_recommendations(title, cosine_sim, indices):
    # Get index of movie that matches title
    idx = ____[____]
    # Sort the movies based on the similarity scores
    sim_scores = list(enumerate(cosine_sim[idx]))
    sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)
    # Get the scores for 10 most similar movies
    sim_scores = sim_scores[____]
    # Get the movie indices
    movie_indices = [i[0] for i in sim_scores]
    # Return the top 10 most similar movies
    return metadata['title'].iloc[movie_indices]
कोड संपादित करें और चलाएँ