简体   繁体   English

是否有可能使用 statsmodels 中的 OLS 以手动声明某些系数的方式指定线性回归?

[英]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 .假设您有两个变量x1x2 ,并且想要设置w1的权重。 You can simply infer你可以简单地推断

w2 =(x2**T * x2) ** (-1) * x2 ** T * (y - w1 * x1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Statsmodels - Wald检验线性回归模型(OLS)中系数趋势的显着性 - Statsmodels - Wald Test for significance of trend in coefficients in Linear Regression Model (OLS) OLS 回归与 statsmodels 给出许多系数 - OLS Regression with statsmodels giving many coefficients 如何使用来自 statsmodels 的 linear_model.OLS 使用 LinearRegression 预测数据 - How to predict data using LinearRegression using linear_model.OLS from statsmodels Pandas Statsmodels使用DF预测器进行回归预测? - Pandas Statsmodels ols regression prediction using DF predictor? 带有正系数的线性回归用于Python中的某些功能 - Linear regression with positive coefficients for SOME of the features in Python 使用OLS回归预测未来值(Python,StatsModels,Pandas) - Predicting out future values using OLS regression (Python, StatsModels, Pandas) 使用 statsmodels 在多元线性回归中添加常量 - Adding a constant in Multiple Linear Regression using statsmodels 使用Python的statsmodels的OLS线性回归进行曲线拟合时,如何选择公式中的常数? - When curve fitting with Python's statsmodels' OLS linear regression, how do I choose the constant in the formula? 为什么statsmodels的OLS中的四次线性回归不匹配LibreOffice Calc? - Why doesn't a quartic linear regression in statsmodels' OLS match LibreOffice Calc? 使用statsmodels进行线性回归 - Linear regression with statsmodels
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM