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

डेटा को लेबल करें

एक dataframe df उपलब्ध है, जिसमें कॉलम endword: string, features: vector, और outvec: vector हैं. आपको वे पंक्तियाँ चुननी हैं जहाँ endword "him" के बराबर हो, और एक कॉलम label जोड़ना है जिसकी integer वैल्यू 1 हो. फिर, union ऑपरेशन का उपयोग करके उतनी ही पंक्तियाँ जोड़ें जहाँ endword him के बराबर न हो, और इन अतिरिक्त पंक्तियों में label = 0 हो.

याद दिलाने के लिए, SQL में not equals तुलना <> से की जाती है.

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

Python में Spark SQL परिचय

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

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

  • lit फंक्शन इम्पोर्ट करें.
  • वे पंक्तियाँ चुनें जहाँ endword 'him' हो और integer कॉलम label वैल्यू 1 के साथ जोड़ें.
  • वे पंक्तियाँ चुनें जहाँ endword 'him' न हो और integer कॉलम label वैल्यू 0 के साथ जोड़ें.
  • इन दोनों सेटों को union करें, और नेगेटिव उदाहरणों की संख्या पॉज़िटिव उदाहरणों की संख्या के बराबर रखें.

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

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

# Import the lit function
from pyspark.____ import lit

# Select the rows where endword is 'him' and label 1
df_pos = df.where("____ = 'him'")\
           .withColumn('label', lit(____))

# Select the rows where endword is not 'him' and label 0
df_neg = df.where("endword <> '____'")\
           .withColumn('label', ____(0))

# Union pos and neg in equal number
df_examples = df_pos.____(df_neg.limit(df_pos.count()))
print("Number of examples: ", df_examples.count())
df_examples.where("endword <> 'him'").sample(False, .1, 42).show(5)
कोड संपादित करें और चलाएँ