[英]Custom Function Linear Regression
I am trying to implement the following "R" code in python: 我正在尝试在python中实现以下“ R”代码:
fit = lm(log(y) ~ log(x1) + log(x2) +
x3, data=data);
I know in sklearn, you can make a linear regression with multiple variables. 我知道在sklearn中,您可以使用多个变量进行线性回归。 However, I specifically want to make the formula above. 但是,我特别想做上面的公式。
Any guidance would be appreciated. 任何指导将不胜感激。
Apply a log transformation to x1
and x2
and then run the linear regression: 对x1
和x2
应用对数转换,然后运行线性回归:
import numpy as np
from sklearn.linear_model import LinearRegression
log_x1 = np.log(x1)
log_x2 = np.log(x2)
log_y = np.log( y)
log_model = LinearRegression().fit( np.c_[log_x1, log_x2, x3], log_y)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.