Categorical कॉलम
flights डेटा में दो कॉलम हैं, carrier और org, जिनमें categorical डेटा है. आपको इन कॉलमों को इंडेक्स किए गए न्यूमेरिक वैल्यूज़ में बदलना है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
PySpark के साथ Machine Learning
अभ्यास निर्देश
- उपयुक्त क्लास इम्पोर्ट करें और
carrierकॉलम को string से numeric इंडेक्स में बदलने के लिए एक indexer ऑब्जेक्ट बनाएँ. - flight डेटा पर indexer ऑब्जेक्ट को तैयार (prepare) करें.
- तैयार किए गए indexer का उपयोग करके न्यूमेरिक इंडेक्स कॉलम बनाएँ.
- यही प्रक्रिया
orgकॉलम के लिए दोहराएँ.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
from pyspark.ml.feature import ____
# Create an indexer
indexer = ____(inputCol=____, outputCol='carrier_idx')
# Indexer identifies categories in the data
indexer_model = indexer.____(flights)
# Indexer creates a new column with numeric index values
flights_indexed = ____.____(____)
# Repeat the process for the other categorical feature
flights_indexed = ____(inputCol=____, outputCol='org_idx').____(____).____(____)
flights_indexed.show(5)