เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

คอลัมน์เชิงหมวดหมู่

ในข้อมูลเที่ยวบินมีสองคอลัมน์ คือ carrier และ org ซึ่งเก็บข้อมูลเชิงหมวดหมู่ คุณต้องแปลงคอลัมน์เหล่านั้นให้เป็นค่าดัชนีตัวเลข

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Machine Learning with PySpark

ดูคอร์ส

คำแนะนำการฝึกหัด

  • นำเข้าคลาสที่เหมาะสม แล้วสร้างออบเจกต์ indexer เพื่อแปลงคอลัมน์ carrier จาก string ให้เป็นดัชนีตัวเลข
  • เตรียม indexer object กับข้อมูลเที่ยวบิน
  • ใช้ 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)
แก้ไขและรันโค้ด