Departure time का Bucketing
दिन के समय (time of day) का डेटा regression मॉडलों के लिए चुनौतीपूर्ण होता है। यह bucketing के लिए भी बेहतरीन कैंडिडेट है.
इस लेसन में आप flight departure times को 0 (00:00 के अनुरूप) से 24 (24:00 के अनुरूप) के बीच के न्यूमेरिक मानों से बिंस (binned) मानों में बदलेंगे। फिर आप उन binned मानों को one-hot encode करेंगे.
यह अभ्यास पाठ्यक्रम का हिस्सा है
PySpark के साथ Machine Learning
अभ्यास निर्देश
- 0, 3, 6, …, 24 पर बिन सीमाओं के साथ एक bucketizer ऑब्जेक्ट बनाएँ, जो 0:00, 03:00, 06:00, …, 24:00 समयों के अनुरूप हैं। इनपुट कॉलम
departऔर आउटपुट कॉलमdepart_bucketनिर्दिष्ट करें. flightsडेटा में departure times को bucket करें।departऔरdepart_bucketके पहले पाँच मान दिखाएँ.- एक one-hot encoder ऑब्जेक्ट बनाएँ, जिसमें
depart_bucketइनपुट कॉलम औरdepart_dummyआउटपुट कॉलम हो. - एन्कोडर को bucketed डेटा पर fit करें और फिर इस डेटा को dummy वैरिएबल्स में transform करने के लिए उपयोग करें।
depart,depart_bucketऔरdepart_dummyके पहले पाँच मान दिखाएँ.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
from pyspark.ml.feature import Bucketizer, OneHotEncoder
# Create buckets at 3 hour intervals through the day
buckets = ____(splits=[____], inputCol='____', outputCol='____')
# Bucket the departure times
bucketed = buckets.____(____)
bucketed.____('____', '____').____(____)
# Create a one-hot encoder
onehot = ____(inputCols=['____'], outputCols=['____'])
# One-hot encode the bucketed departure times
flights_onehot = ____.____(____).____(____)
flights_onehot.____('____', '____', '____').____(____)