[英]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.