Giới thiệu về kiểm định mô hình

Xác thực Mô hình trong Python

Kasey Jones

Data Scientist

Kiểm định mô hình là gì?

Kiểm định mô hình gồm:

  • Đảm bảo mô hình hoạt động đúng trên dữ liệu mới
  • Kiểm tra hiệu năng trên tập giữ lại (holdout)
  • Chọn mô hình, tham số và thước đo độ chính xác tốt nhất
  • Đạt độ chính xác cao nhất cho dữ liệu hiện có
Xác thực Mô hình trong Python

Ôn tập mô hình hóa với scikit-learn

Các bước mô hình hóa cơ bản:

model = RandomForestRegressor(n_estimators=500, random_state=1111)

model.fit(X=X_train, y=y_train)
RandomForestRegressor(bootstrap=True, criterion='mse', max_depth=None,
           max_features='auto', max_leaf_nodes=None,
           min_impurity_decrease=0.0, min_impurity_split=None,
           min_samples_leaf=1, min_samples_split=2,
           min_weight_fraction_leaf=0.0, n_estimators=500, n_jobs=1,
           oob_score=False, random_state=1111, verbose=0, warm_start=False)
Xác thực Mô hình trong Python

Ôn tập (tiếp)

predictions = model.predict(X_test)

print("{0:.2f}".format(mae(y_true=y_test, y_pred=predictions)))
10.84

Công thức Sai số Tuyệt đối Trung bình (MAE)

$$ \frac{\sum_{i=1}^{n} |y_i - \hat{y}_i|}{n} $$

Xác thực Mô hình trong Python

Ôn lại kiến thức nền

Xác thực Mô hình trong Python

Fivethirtyeight có vài bộ dữ liệu, gồm bảng xếp hạng kẹo Halloween. Mỗi loại kẹo có tỷ lệ thắng đối đầu từ 0 đến 100%.

Xác thực Mô hình trong Python

Dữ liệu đã thấy vs. chưa thấy

Dữ liệu huấn luyện = dữ liệu đã thấy

model = RandomForestRegressor(n_estimators=500, random_state=1111)
model.fit(X_train, y_train)
train_predictions = model.predict(X_train)

Dữ liệu kiểm tra = dữ liệu chưa thấy

model = RandomForestRegressor(n_estimators=500, random_state=1111)
model.fit(X_train, y_train)
test_predictions = model.predict(X_test)
Xác thực Mô hình trong Python

Bắt đầu nào!

Xác thực Mô hình trong Python

Preparing Video For Download...