2016-01-11 18 views
6

lmplotは、切片を伴う海底適合回帰モデルである。しかし、回帰モデルを代入することなくの回帰モデル、すなわち起点を通る回帰にフィットしたいことがあります。例えば`lmplot`を使って線形回帰を傍受せずにプロットするには?

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

私が望んでフィギュア:

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

オプションはありません。 – mwaskom

+0

@mwaskom将来それをサポートする計画はありますか? – Eastsun

+0

申し訳ありません。 – mwaskom

答えて

0

このスーツをあなたの目的にしていますか?

sns.lmplot(x='x', y='y', data=df, fit_reg=False) 
関連する問題