開始使用免費開始

使用 Dask 訓練線性模型

Dask 可用來在無法完全載入記憶體的資料集上訓練機器學習模型,並讓你把資料載入、前處理與訓練分散到多個執行緒、程序,甚至多台電腦上。

你需要訓練一個機器學習模型,來預測你在前幾章使用過的 Spotify 資料集中歌曲的受歡迎程度。資料已經以 lazy 的 Dask DataFrame 載入。輸入變數存在 dask_X,包含一些數值欄位,例如歌曲的節奏(tempo)與可舞性(danceability)。目標值存在 dask_y,代表每首歌的受歡迎程度分數。

本練習屬於課程

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

檢視課程

練習說明

  • sklearn.linear_model 匯入 SGDRegressor 類別,並從 dask_ml.wrappers 匯入 Incremental 類別。
  • 建立一個 SGDRegressor 線性迴歸模型。
  • 使用 Incremental 類別包裝模型,使其能用 Dask 資料集訓練,並將 scoring 參數設為 'neg_mean_squared_error'
  • 僅透過資料跑一圈迴圈來訓練這個包裝後的模型。

動手互動練習

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

# Import the SGDRegressor and the Incremental wrapper
from ____ import ____
from ____ import ____

# Create a SGDRegressor model
model = ____

# Wrap the model so that it works with Dask
dask_model = ____

# Fit the wrapped model
dask_model.____
編輯並執行程式碼