Categorical कॉलम
flights डेटा में दो कॉलम, carrier और org, श्रेणीबद्ध (categorical) डेटा रखते हैं. आपको इन कॉलमों को इंडेक्स किए गए संख्यात्मक मानों में ट्रांसफॉर्म करना है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
PySpark के साथ Machine Learning
अभ्यास निर्देश
- उपयुक्त क्लास इम्पोर्ट करें और एक indexer ऑब्जेक्ट बनाएँ ताकि
carrierकॉलम को string से numeric index में ट्रांसफॉर्म किया जा सके. - flight डेटा पर indexer ऑब्जेक्ट को तैयार (prepare) करें.
- तैयार किए गए indexer का उपयोग करके numeric index कॉलम बनाएँ.
- यही प्रक्रिया
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)