Bộ phân loại tuyến tính: phương trình dự đoán

Bộ phân loại tuyến tính với Python

Michael (Mike) Gelbart

Instructor, The University of British Columbia

Tích vô hướng

x = np.arange(3)
x
array([0, 1, 2])
y = np.arange(3,6)
y
array([3, 4, 5])
x*y
array([0, 4, 10])
np.sum(x*y)
14
x@y
14
  • x@y gọi là tích vô hướng của x và y, ký hiệu $x \cdot y$.
Bộ phân loại tuyến tính với Python

Dự đoán của bộ phân loại tuyến tính

  • $\textrm{raw model output} = \textrm{coefficients} \cdot \textrm{features} + \textrm{intercept}$
  • Dự đoán của bộ phân loại tuyến tính: tính raw model output, kiểm tra dấu
    • dương: dự đoán một lớp
    • âm: dự đoán lớp còn lại
  • Áp dụng như nhau cho logistic regression và linear SVM
    • fit khác nhau nhưng predict giống nhau
Bộ phân loại tuyến tính với Python

LogisticRegression dự đoán như thế nào

$\textrm{raw model output} = \textrm{coefficients} \cdot \textrm{features} + \textrm{intercept}$

lr = LogisticRegression()

lr.fit(X,y)

lr.predict(X)[10]
0
lr.predict(X)[20]
1
Bộ phân loại tuyến tính với Python

LogisticRegression dự đoán như thế nào (tiếp)

lr.coef_ @ X[10] + lr.intercept_ # raw model output
array([-33.78572166])
lr.coef_ @ X[20] + lr.intercept_ # raw model output
array([ 0.08050621])
Bộ phân loại tuyến tính với Python

Raw model output

Bộ phân loại tuyến tính với Python

Raw model output

Bộ phân loại tuyến tính với Python

Raw model output

Bộ phân loại tuyến tính với Python

Cùng luyện tập nào!

Bộ phân loại tuyến tính với Python

Preparing Video For Download...