開始使用免費開始

延遲的訓練/測試切分

你已經轉換了 X 變數。接下來需要完成資料前處理,將 y 變數也做轉換,並把資料切分為訓練集與測試集。

你在上一個練習建立的變數 Xy 已可在你的環境中使用。

本練習屬於課程

在 Python 中使用 Dask 進行平行程式設計

檢視課程

練習說明

  • dask_ml.model_selection 匯入 train_test_split() 函式。
  • y 中的熱門度分數介於 0-100,請將它們除以 100,使其落在 0-1 的範圍。
  • 使用 train_test_split() 將資料切分為訓練集與測試集,記得隨機重排(shuffle)資料,並將測試集比例設為資料的 20%。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import the train_test_split function
from ____ import ____

# Rescale the target values
y = ____

# Split the data into train and test sets
X_train, X_test, y_train, y_test = ____

print(X_train)
編輯並執行程式碼