使用SciPy进行线性回归分析的步骤如下:
import numpy as np
from scipy import stats
x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 3, 5, 4, 6])
linregress
函数进行线性回归分析:slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
print("斜率:", slope)
print("截距:", intercept)
print("相关系数:", r_value)
print("p值:", p_value)
通过上述步骤,你就可以使用SciPy进行线性回归分析了。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: NumPy如何与SciPy集成使用