[英]how to plot on a graph using the hypothesis function by substituting the value of theta 0 and theta 1
这是假设函数h(x)= theta 0 + theta 1(x)将theta 0的值设为0并将theta 1的值设为0.5之后,如何将其绘制在图形上?
It is the same way that we graph the linear equations. 我们绘制线性方程式的方法也一样。 Let us assume h(x) as y and θ as some constant and x as x.
让我们假设h(x)为y,θ为某个常数,x为x。 So we basically have a linear expression like this y = m + p * x (m,p are constants) .
因此,我们基本上有一个线性表达式,例如y = m + p * x(m,p是常数)。 To even simplify it assume the function as y = 2 + 4x.
为了简化计算,假设函数为y = 2 + 4x。 To plot this we will just assume the values of x from a range (0,5) so now for each value of x we will have corresponding value of x.
为了对此进行绘制,我们仅假设x的值在(0,5)范围内,因此现在对于x的每个值,我们将具有x的对应值。 so our (x,y) set will look like this ([0, 1, 2, 3, 4], [2, 6, 10, 14, 18]).
因此我们的(x,y)集看起来像这样[[0,1,2,3,4],[2,6,10,14,18])。 Now the graph can be plotted as we know both x and y coords.
现在可以绘制图形,因为我们知道x和y坐标。
You simply plot the line equation y = 0 + 0.5 * x
您只需绘制线方程
y = 0 + 0.5 * x
So you get something like this plot 所以你得到这样的情节
Here's how I did it with Python 这是我使用Python做到的方式
import matplotlib.pyplot as plt
import numpy as np
theta_0 = 0
theta_1 = 0.5
def h(x):
return theta_0 + theta_1 * x
x = range(-100, 100)
y = map(h, x)
plt.plot(x, y)
plt.ylabel(r'$h_\theta(x)$')
plt.xlabel(r'$x$')
plt.title(r'Plot of $h_\theta(x) = \theta_0 + \theta_1 \cdot \ x$')
plt.text(60, .025, r'$\theta_0=0,\ \theta_1=0.5$')
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.