Linear classifiers: สมการการพยากรณ์

Linear Classifiers ใน Python

Michael (Mike) Gelbart

Instructor, The University of British Columbia

Dot Products

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 เรียกว่า dot product ของ x และ y เขียนแทนด้วย $x \cdot y$
Linear Classifiers ใน Python

การพยากรณ์ของ linear classifier

  • $\textrm{raw model output} = \textrm{coefficients} \cdot \textrm{features} + \textrm{intercept}$
  • การพยากรณ์ของ linear classifier: คำนวณ raw model output แล้วตรวจสอบเครื่องหมาย
    • ถ้าเป็นบวก พยากรณ์คลาสหนึ่ง
    • ถ้าเป็นลบ พยากรณ์อีกคลาสหนึ่ง
  • ทั้ง logistic regression และ linear SVM ใช้หลักการเดียวกัน
    • fit ต่างกัน แต่ predict เหมือนกัน
Linear Classifiers ใน Python

LogisticRegression พยากรณ์อย่างไร

$\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
Linear Classifiers ใน Python

LogisticRegression พยากรณ์อย่างไร (ต่อ)

lr.coef_ @ X[10] + lr.intercept_ # raw model output
array([-33.78572166])
lr.coef_ @ X[20] + lr.intercept_ # raw model output
array([ 0.08050621])
Linear Classifiers ใน Python

Raw model output

Linear Classifiers ใน Python

Raw model output

Linear Classifiers ใน Python

Raw model output

Linear Classifiers ใน Python

มาฝึกกันเถอะ!

Linear Classifiers ใน Python

Preparing Video For Download...