Huấn luyện mô hình học máy trên dữ liệu lớn

Lập trình song song với Dask trong Python

James Fulton

Climate Informatics Researcher

Dask-ML

import dask_ml
  • Tăng tốc các tác vụ học máy
Lập trình song song với Dask trong Python

Hồi quy tuyến tính

Ví dụ dữ liệu có quan hệ tuyến tính giữa x và y.

Lập trình song song với Dask trong Python

Hồi quy tuyến tính

Một đường thẳng đã được fit vào dữ liệu.

Lập trình song song với Dask trong Python

Hồi quy tuyến tính

Khoảng cách giữa đường thẳng và các điểm dữ liệu thực được đánh dấu.

Lập trình song song với Dask trong Python

Fit mô hình hồi quy tuyến tính

# Import regression model
from sklearn.linear_model import SGDRegressor

# Create instance of model
model = SGDRegressor()

# Fit model to data
model.fit(X, y)

# Make predictions
y_pred = model.predict(X)
Lập trình song song với Dask trong Python

Dùng mô hình scikit-learn với Dask

# Import regression model
from sklearn.linear_model import SGDRegressor

# Create instance of model
model = SGDRegressor()


# Import Dask-ML wrapper for model from dask_ml.wrappers import Incremental
# Wrap model dask_model = Incremental(model, scoring='neg_mean_squared_error')
# Fit on Dask DataFrames or arrays dask_model.fit(dask_X, dask_y) # not lazy
Lập trình song song với Dask trong Python

Fit cần nhiều lần lặp

Hoạt ảnh cho thấy đường thẳng khớp chính xác hơn sau nhiều lần lặp việc fit.

Lập trình song song với Dask trong Python

Huấn luyện mô hình Incremental

# Loop through data multiple times
for i in range(10):
    dask_model.partial_fit(dask_X, dask_y)  # not lazy    
Lập trình song song với Dask trong Python

Tạo dự đoán

y_pred = dask_model.predict(dask_X)

print(y_pred)
dask.array<_predict, shape=(nan,), dtype=int64, chunksize=(nan,), chunktype=...>
print(y_pred.compute())
array([0.465557, 0.905675, 0.285214, ..., 0.249454, 0.559624, 0.823475])
Lập trình song song với Dask trong Python

Ayo berlatih!

Lập trình song song với Dask trong Python

Preparing Video For Download...