[英]Is there possibility to specify a linear regression using a OLS from statsmodels in way that some coefficients are declare manually?
I want to build linear regression by using OLS from statsmodels.我想通过使用 statsmodels 中的 OLS 来构建线性回归。 I have a question about manually declaration of coefficients for some explanatory variables.我有一个关于手动声明一些解释变量的系数的问题。
Is there possibility to parameterize a model in way that for 4 from 10 variables I will put manually coefficients and for rest the fit method will count the values of them?是否有可能对 model 进行参数化,对于 10 个变量中的 4 个,我将手动放置系数,对于 rest,拟合方法将计算它们的值?
Or maybe you know a different way haw to do it?或者,也许您知道另一种方法来做到这一点?
Many thanks for all answers!非常感谢所有的答案!
MP国会议员
Yes, in two steps.是的,分两步。 First you take those manual coefficients, multiply them with the corresponding ('manual') variables to get vectors, and subtract them from the target.首先,您获取这些手动系数,将它们与相应的(“手动”)变量相乘以获得向量,然后从目标中减去它们。 Then, you can take a normal OLS and get the coefficients of the remaining variables.然后,您可以采用正态 OLS 并获取剩余变量的系数。
Say you have two variables, x1
and x2
, and want to set the weight for w1
.假设您有两个变量x1
和x2
,并且想要设置w1
的权重。 You can simply infer你可以简单地推断
w2 =(x2**T * x2) ** (-1) * x2 ** T * (y - w1 * x1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.