簡體   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