2744557306 发表于 2024-3-15 17:09

使用 sklearn 进行多元线性回归

多元线性回归是一种强大的统计方法,适用于探索多个自变量与因变量之间的复杂关系,并进行预测和解释。
# %%import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
# %%

# 源数据df = pd.DataFrame({
    'x1': ,
    'x2': ,
    'y': ,
})

X = np.array(df[['x1','x2']])
y = np.array(df[['y']])# 多元线性回归模型model = LinearRegression().fit(X, y)
# %%

# 截距
b0 = model.intercept_

# 系数
b1, b2 = model.coef_

print('y = {:.4f} + {:.4f}*x1 + {:.4f}*x2'.format(b0, b1,b2))
print('R_square =',model.score(X,y))


页: [1]
查看完整版本: 使用 sklearn 进行多元线性回归