Python 生成回归方程:使用 scikit-learn 实现线性回归
要生成回归方程,可以使用 Python 中的机器学习库,如 scikit-learn。以下是一个简单的示例,使用线性回归模型来生成回归方程:
import numpy as np
from sklearn.linear_model import LinearRegression
# 生成一些随机数据作为示例
X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
y = np.dot(X, np.array([1, 2])) + 3
# 创建线性回归模型
model = LinearRegression()
# 拟合数据
model.fit(X, y)
# 打印回归方程的系数和截距
print('回归方程的系数:', model.coef_)
print('回归方程的截距:', model.intercept_)
运行以上代码,将会得到回归方程的系数和截距。在这个例子中,回归方程可以表示为 y = 1x1 + 2x2 + 3。
原文地址: https://www.cveoy.top/t/topic/qBRE 著作权归作者所有。请勿转载和采集!