简体   繁体   English

以下代码中使用什么公式来计算ys?

[英]What formula is being used to calculate ys in the following code?

I'm not able to understand the formula for predicting the ys to plot the graph. 我无法理解用于预测绘制图表的ys的公式。

How can it be ys = (-theta[0] - theta[1] * xs) / theta[2] ? 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')

Here you don't predict ys , in the formula both xs and ys are your features, so probably better name them x1 and x2 . 在这里,您不会预测ys ,在公式中xsys都是您的特征,因此最好将它们命名为x1x2

This formulas both define the same decision boundary: 这两个公式都定义了相同的决策边界:

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

But to plot the boundary you should define one feature with other. 但是要绘制边界,您应该定义一个特征和另一个特征。

So here ys are not your predictions your prediction is the sign of this expression which depends of two features xs and ys : 因此,这里ys不是您的预测,您的预测是该表达式的符号,它取决于xsys两个特征:

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

on the plot this is line which divide your points in two groups. 在图中,这是将您的点分为两组的线。 I attached screenshot from your link where this describes. 我附上了您描述此链接的屏幕截图。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 此代码中使用的运算符==和*是什么? - What are the operators == and * being used for in this code? 以下代码中的 else 块不起作用,仅执行 if 语句来计算体积。 出了什么问题? - the else block in the following code isn't working and only the if statement is being executed to calculate the volume. What is going wrong? 使用什么来检查 Django 中的代码覆盖率? - What's being used to check code coverage in Django? 这个 1 在下面的代码中代表什么? - What this 1 stands for in following code? 为什么 pytorch 中的正则化和 scratch code 不匹配,pytorch 中正则化的公式是什么? - Why does regularization in pytorch and scratch code does not match and what is the formula used for regularization in pytorch? 如何根据下面的代码用公式手动计算 - how to calculate manually with the formula according to the code below pandas - 列出用于计算滚动的数据? - pandas - List data being used to calculate rolling? 为什么我在以下代码中使用的相同的Magic方法会生成与预期不同的输出 - Why is the same Magic method I used in the following code generating different output than what is expected 以下代码中以下参数的用途是什么? - What is the use of following parameter in the following code? 此代码与此公式有什么区别? - What is the difference between this code and this formula?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM