開始使用免費開始

延後執行地轉換訓練資料

在機器學習中,前處理輸入變數是關鍵步驟,通常能提升你所建立模型的準確度。前兩個練習中已替你前處理了 Spotify 資料,但你自己會做也很重要。

在本練習中,你將使用 StandardScaler() 縮放器物件,將陣列的各欄轉換為平均數為 0、標準差為 1 的分佈。

環境中已提供 Spotify 歌曲的 Dask DataFrame,變數名稱為 dask_df。其中包含作為目標的熱門度分數,以及你用來預測這些分數的輸入變數。

本練習屬於課程

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

檢視課程

練習說明

  • dask_ml.preprocessing 匯入 StandardScaler() 類別。
  • 從 DataFrame 中選出 'popularity' 欄並指派給變數 y
  • 建立一個 StandardScaler 物件,並以 X 資料進行擬合(fit)。
  • 使用縮放器轉換 X

動手互動練習

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

# Import the StandardScaler class
from ____ import ____

X = dask_df[['duration_ms', 'explicit', 'danceability', 'acousticness', 'instrumentalness', 'tempo']]

# Select the target variable
y = ____

# Create a StandardScaler object and fit it on X
scaler = ____
scaler.____(____)

# Transform X
X = scaler.____
print(X)
編輯並執行程式碼