我不明白用于预测ys以绘制图表的公式是什么。
怎么可能是 ys = (-theta[0] - theta[1] * xs) / theta[2]
?
fig, axes = plt.subplots(1, 3, sharex=True, sharey=True, figsize=(12, 3))axes = axes.ravel()for k, theta in enumerate(tha[:3]): ax = axes[k] xs = np.arange(0, 1, 0.1) ys = (-theta[0] - theta[1] * xs) / theta[2] ax.plot(xs, ys, lw=0.5) dfa.query('label == 1').plot.scatter(x='x1', y='x2', ax=ax, color='blue') dfa.query('label == -1').plot.scatter(x='x1', y='x2', ax=ax, color='red')
回答:
这里你并没有预测 ys
,在公式中 xs
和 ys
都是你的特征,因此最好将它们命名为 x1
和 x2
。
这两个公式定义了相同的决策边界:
ys = (-theta[0] - theta[1] * xs) / theta[2]theta[2] * ys = (-theta[0] - theta[1] * xs)
但为了绘制边界,你应该用一个特征来定义另一个特征。
所以这里的 ys
不是你的预测,你的预测是这个表达式符号,它依赖于两个特征 xs
和 ys
:
theta[0] + theta[1] * xs + theta[2] * ys
在图表上,这条线将你的点分为两组。我附上了你链接中的截图,解释了这一点。