【问题标题】:What formula is being used to calculate ys in the following code?以下代码中使用什么公式计算 ys?
【发布时间】:2019-07-25 22:01:19
【问题描述】:

我无法理解预测 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')

【问题讨论】:

  • 你能指定你的 thetas 来自哪里吗?
  • theta_0、theta_1 和 theta_2 是模型训练参数。
  • 我明白了,您能提供有关模型的更多详细信息吗?
  • 在这个网站上:gtraskas.github.io/post/ex2评估逻辑回归部分下,他们使用了相同的公式(即 plot_y = -(theta[0] + theta[1] * plot_x ) / theta[2] ) 用于预测 y。但如果从哪里来?
  • 用截图给你一些解释。对不起我的英语不好。如果需要可以为您提供一些额外的链接。

标签: python machine-learning logistic-regression


【解决方案1】:

这里你不要预测ys,在公式中xsys都是你的特征,所以最好将它们命名为x1x2

这两个公式都定义了相同的决策边界:

ys = (-theta[0] - theta[1] * xs) / theta[2]
theta[2] * ys = (-theta[0] - theta[1] * xs)

但要绘制边界,您应该定义一个特征与另一个特征。

所以这里ys 不是你的预测,你的预测是标志 这个表达式取决于 xsys 两个特征:

 theta[0] + theta[1] * xs + theta[2] * ys

在图上,这条线将您的点分为两组。我附上了您描述的链接中的屏幕截图。

【讨论】:

    猜你喜欢
    • 2012-02-24
    • 1970-01-01
    • 2020-05-16
    • 2020-12-07
    • 2022-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多