फ़्लाइट origin को एन्कोड करना
flights डेटा में org कॉलम एक categorical वैरिएबल है जो उस एयरपोर्ट को दर्शाता है जहाँ से फ़्लाइट प्रस्थान करती है.
- ORD — O'Hare International Airport (Chicago)
- SFO — San Francisco International Airport
- JFK — John F Kennedy International Airport (New York)
- LGA — La Guardia Airport (New York)
- SMF — Sacramento
- SJC — San Jose
- OGG — Kahului (Hawaii)
यह स्पष्ट तौर पर एयरपोर्ट्स का केवल एक छोटा subset है. फिर भी, क्योंकि यह एक categorical वैरिएबल है, इसे regression मॉडल में इस्तेमाल करने से पहले one-hot encode करना ज़रूरी है.
डेटा flights नाम के वैरिएबल में है. आप पहले ही org में मौजूद strings के अनुरूप indexed वैल्यूज़ वाला कॉलम बनाने के लिए string indexer का उपयोग कर चुके हैं.
आपको IPython Shell के बगल में Slides पैनल में मौजूद लेसन की स्लाइड्स दोहराकर देखना उपयोगी लग सकता है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
PySpark के साथ Machine Learning
अभ्यास निर्देश
- One-hot encoder क्लास इम्पोर्ट करें.
- एक one-hot encoder इंस्टेंस बनाएँ, जिसमें input कॉलम
org_idxऔर output कॉलमorg_dummyहो. - flights डेटा पर one-hot encoder अप्लाई करें.
- categorical वैल्यूज़ से binary encoded dummy वैरिएबल्स की मैपिंग का सारांश जनरेट करें. केवल यूनिक वैल्यूज़ शामिल करें और
org_idxके अनुसार ऑर्डर करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import the one hot encoder class
from pyspark.ml.____ import ____
# Create an instance of the one hot encoder
onehot = ____(inputCols=[____], outputCols=[____])
# Apply the one hot encoder to the flights data
onehot = onehot.____(____)
flights_onehot = onehot.____(____)
# Check the results
flights_onehot.____('org', 'org_idx', 'org_dummy').____().____('org_idx').show()