繁体   English   中英

如何通过替换theta 0和theta 1的值使用假设函数在图形上进行绘制

[英]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之后,如何将其绘制在图形上?

我们绘制线性方程式的方法也一样。 让我们假设h(x)为y,θ为某个常数,x为x。 因此,我们基本上有一个线性表达式,例如y = m + p * x(m,p是常数)。 为了简化计算,假设函数为y = 2 + 4x。 为了对此进行绘制,我们仅假设x的值在(0,5)范围内,因此现在对于x的每个值,我们将具有x的对应值。 因此我们的(x,y)集看起来像这样[[0,1,2,3,4],[2,6,10,14,18])。 现在可以绘制图形,因为我们知道x和y坐标。

您只需绘制线方程y = 0 + 0.5 * x

所以你得到这样的情节 在此处输入图片说明

这是我使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM