线性分类器:预测方程

Python 中的线性分类器

Michael (Mike) Gelbart

Instructor, The University of British Columbia

点积

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 称为 xy 的点积,记作 $x \cdot y$。
Python 中的线性分类器

线性分类器的预测

  • $\textrm{原始输出} = \textrm{系数} \cdot \textrm{特征} + \textrm{截距}$
  • 线性分类器预测:先算原始输出,再看其符号
    • 为正,预测一类
    • 为负,预测另一类
  • 逻辑回归与线性 SVM 相同
    • fit 不同,但 predict 相同
Python 中的线性分类器

LogisticRegression 如何预测

$\textrm{原始输出} = \textrm{系数} \cdot \textrm{特征} + \textrm{截距}$

lr = LogisticRegression()

lr.fit(X,y)

lr.predict(X)[10]
0
lr.predict(X)[20]
1
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])
Python 中的线性分类器

模型原始输出

Python 中的线性分类器

模型原始输出

Python 中的线性分类器

模型原始输出

Python 中的线性分类器

Vamos praticar!

Python 中的线性分类器

Preparing Video For Download...