[英]How do I calculate y for every value of x if the slope a set to 10 and the intercept b to 0?
如果您的斜率已經設置為 10,我不明白為什么需要使用線性回歸。 我希望我不會從你的任務中遺漏任何東西。
但是,如果您需要在 python 中獲取所有元素乘以斜率a
的列表,則保留這一點,那么您可以使用列表推導通過以下方式找到這個新列表:
y_computed = [item*a for item in x]
您實際上可以在同一 plot 上繪制一條具有恆定斜率 (10) 的線,然后根據該線“估計”計算預測的 y 值(如果需要,您還可以找到估計的誤差)。 這可以使用以下方法完成:
import numpy as np
from matplotlib import pyplot as plt
def const_line(x):
y = 10 * x + 0 # Just to illustrate that the intercept is zero
return y
x = np.linspace(0, 1)
y = const_line(x)
plt.plot(x, y, c='m')
plt.show()
# Find the y-values for each sample point in your data:
for x in data:
const_line(x)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.