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

सही फ़ॉर्मेट और विशिष्ट users

R डेटाफ़्रेम पर नज़र डालिए। ध्यान दें कि यह पारंपरिक या "wide" फ़ॉर्मेट में है जहाँ हर कॉलम में एक अलग मूवी है। यह भी देखें कि User और मूवी के नाम integer फ़ॉर्मेट में नहीं हैं। ALS के लिए इस डेटा को ठीक से तैयार करने के लिए दिए गए चरणों का पालन करें.

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

PySpark के साथ Recommendation Engines बनाना

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

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

  • pyspark.sql.functions से monotonically_increasing_id पैकेज इम्पोर्ट करें और .show() मेथड का उपयोग करके R डेटाफ़्रेम देखें.
  • to_long() फंक्शन का उपयोग करके R डेटाफ़्रेम को "long" डेटाफ़्रेम में बदलें. नए डेटाफ़्रेम को ratings नाम दें.
  • users नाम का एक डेटाफ़्रेम बनाएँ जिसमें डेटाफ़्रेम से सभी .distinct() users हों, और .coalesce(1) मेथड का उपयोग करके डेटाफ़्रेम को एक ही पार्टीशन में रिपार्टिशन करें.
  • withColumn() के अंदर monotonically_increasing_id() मेथड का उपयोग करके users डेटाफ़्रेम में एक नया कॉलम बनाएँ जिसमें हर user के लिए एक unique integer हो. इस कॉलम का नाम userId रखें. सुनिश्चित करें कि नए integer IDs बने रहें, इसके लिए अंतिम डेटाफ़्रेम पर .persist() मेथड कॉल करें.

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

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

# Import monotonically_increasing_id and show R
from pyspark.sql.functions import ____
R.show()

# Use the to_long() function to convert the dataframe to the "long" format.
ratings = to_long(____)
ratings.show()

# Get unique users and repartition to 1 partition
users = ratings.select("____").____().____()

# Create a new column of unique integers called "userId" in the users dataframe.
users = users.withColumn("____", monotonically_increasing_id()).____()
users.show()
कोड संपादित करें और चलाएँ