2016-01-11 5 views
6

Die lmplot in Seaborn Fit Regressionsmodelle mit Intercept. Manchmal möchte ich jedoch Regressionsmodelle ohne Intercept anpassen, d. H. Regression durch den Ursprung.Wie benutzt man `lmplot` um lineare Regression ohne Intercept darzustellen?

Zum Beispiel:

In [1]: import numpy as np 
    ...: import pandas as pd 
    ...: import seaborn as sns 
    ...: import matplotlib.pyplot as plt 
    ...: import statsmodels.formula.api as sfa 
    ...: 

In [2]: %matplotlib inline 
In [3]: np.random.seed(2016) 
In [4]: x = np.linspace(0, 10, 32) 
In [5]: y = 0.3 * x + np.random.randn(len(x)) 
In [6]: df = pd.DataFrame({'x': x, 'y': y}) 
In [7]: r = sfa.ols('y ~ x + 0', data=df).fit() 
In [8]: sns.lmplot(x='x', y='y', data=df, fit_reg=True) 
Out[8]: <seaborn.axisgrid.FacetGrid at 0xac88a20> 

enter image description here

Die Figur, was ich wollte:

In [9]: fig, ax = plt.subplots(figsize=(5, 5)) 
    ...: ax.scatter(x=x, y=y) 
    ...: ax.plot(x, r.fittedvalues) 
    ...: 
Out[9]: [<matplotlib.lines.Line2D at 0x5675a20>] 

enter image description here

+1

Keine Option, sorry. – mwaskom

+0

@mwaskom Gibt es einen Plan, es in Zukunft zu unterstützen? – Eastsun

+0

Nicht wahrscheinlich, sorry. – mwaskom

Antwort

0

Ist dies Ihr Zweck Anzug?

sns.lmplot(x='x', y='y', data=df, fit_reg=False) 
Verwandte Themen