线性回归 - 减少自由度

Fem*_*der 9 python statistics numpy curve-fitting pandas

我有一个Pandas数据框,列有像

Order     Balance     Profit cum (%)
Run Code Online (Sandbox Code Playgroud)

我正在进行线性回归

model_profit_tr = pd.ols(y=df_closed['Profit cum (%)'], x=df_closed['Order'])
Run Code Online (Sandbox Code Playgroud)

这个问题是标准模型就像(不通过原点的线的方程)

y = a * x + b
Run Code Online (Sandbox Code Playgroud)

有2个自由度(a和b)

斜坡(a):

a=model_profit_tr.beta['x']
Run Code Online (Sandbox Code Playgroud)

和截距(b):

b=model_profit_tr.beta['intercept']
Run Code Online (Sandbox Code Playgroud)

我想减少我的模型的自由度(从2到1),我希望有一个类似的模型

y = a * x
Run Code Online (Sandbox Code Playgroud)

Ava*_*ris 8

使用intercept关键字参数:

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

来自docs:

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]
Run Code Online (Sandbox Code Playgroud)