航班飛行時間模型:Pipeline 模型
你現在已經可以把這些階段串成一個 pipeline。
你將建立 pipeline,然後在訓練資料上訓練它。這會依序把 pipeline 中的每個階段套用到訓練資料。任何階段都不會接觸到測試資料:不會有洩漏!
整個 pipeline 訓練完成後,會用來對測試資料進行預測。
資料以 flights 提供,並已隨機切分為 flights_train 與 flights_test。
本練習屬於課程
使用 PySpark 的機器學習
練習說明
- 匯入用來建立 pipeline 的類別。
- 建立一個 pipeline 物件,並依序指定
indexer、onehot、assembler、regression這些階段。 - 在訓練資料上訓練該 pipeline。
- 針對測試資料進行預測。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import class for creating a pipeline
from pyspark.____ import ____
# Construct a pipeline
pipeline = ____(____=[____])
# Train the pipeline on the training data
pipeline = pipeline.____(____)
# Make predictions on the testing data
predictions = ____.____(____)