我有一个Pandas数据框,其中包含诸如

Order     Balance     Profit cum (%)

我正在做线性回归
model_profit_tr = pd.ols(y=df_closed['Profit cum (%)'], x=df_closed['Order'])

问题在于标准模型就像(不穿过原点的线的等式)
y = a * x + b

有2个自由度(a和b)

斜率(a):
a=model_profit_tr.beta['x']

并拦截(b):
b=model_profit_tr.beta['intercept']

我想将模型的自由度(从2降低到1),并且希望有一个像
y = a * x

最佳答案

使用intercept关键字参数:

model_profit_tr = pd.ols(y=df_closed['Profit cum (%)'],
                         x=df_closed['Order'],
                         intercept=False)

从文档:
In [65]: help(pandas.ols)
Help on function ols in module pandas.stats.interface:

ols(**kwargs)

    [snip]

    Parameters
    ----------
    y: Series or DataFrame
        See above for types
    x: Series, DataFrame, dict of Series, dict of DataFrame, Panel
    weights : Series or ndarray
        The weights are presumed to be (proportional to) the inverse of the
        variance of the observations.  That is, if the variables are to be
        transformed by 1/sqrt(W) you must supply weights = 1/W
    intercept: bool
        True if you want an intercept.  Defaults to True.
    nw_lags: None or int
        Number of Newey-West lags.  Defaults to None.

    [snip]

关于python - 线性回归-降低自由度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12664590/

10-12 15:37