Python图形难度大

时间:2014-09-12 19:04:42

标签: python-2.7 anaconda

from __future__ import print_function
import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt
from statsmodels.sandbox.regression.predstd import wls_prediction_std

np.random.seed(9876789)

nsample = 50
sig = 0.5
x = np.linspace(0, 20, nsample)
X = np.column_stack((x, np.sin(x), (x-5)**2, np.ones(nsample)))
beta = [0.5, 0.5, -0.02, 5.]

y_true = np.dot(X, beta)
y = y_true + sig * np.random.normal(size=nsample)

res = sm.OLS(y, X).fit()
print(res.summary())

print('Parameters: ', res.params)
print('Standard errors: ', res.bse)


prstd, iv_l, iv_u = wls_prediction_std(res)

fig, ax = plt.subplots(figsize=(8,6))

ax.plot(x, y, 'o', label="data")
ax.plot(x, y_true, 'b-', label="True")
ax.plot(x, res.fittedvalues, 'r--.', label="OLS")
ax.plot(x, iv_u, 'r--')
ax.plot(x, iv_l, 'r--')
ax.legend(loc='best');

我对此的看法是:

OLS Regression Results                            
==============================================================================
Dep. Variable:                      y   R-squared:                       0.920
Model:                            OLS   Adj. R-squared:                  0.915
Method:                 Least Squares   F-statistic:                     175.9
Date:                Fri, 12 Sep 2014   Prob (F-statistic):           3.30e-25
Time:                        13:00:23   Log-Likelihood:                -38.308
No. Observations:                  50   AIC:                             84.62
Df Residuals:                      46   BIC:                             92.26
Df Model:                           3                                         
==============================================================================
                 coef    std err          t      P>|t|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
x1             0.4704      0.029     16.487      0.000         0.413     0.528
x2             0.2931      0.112      2.613      0.012         0.067     0.519
x3            -0.0183      0.003     -7.290      0.000        -0.023    -0.013
const          5.2494      0.185     28.375      0.000         4.877     5.622
==============================================================================
Omnibus:                        1.779   Durbin-Watson:                   2.359
Prob(Omnibus):                  0.411   Jarque-Bera (JB):                1.440
Skew:                           0.414   Prob(JB):                        0.487
Kurtosis:                       2.933   Cond. No.                         221.
==============================================================================
Parameters:  [ 0.47040466  0.2931004  -0.01826292  5.24935422]
Standard errors:  [ 0.02853117  0.11215937  0.00250506  0.18499717]

没有任何图表。有什么我忘记或遗失的东西?目前我只是试图测试anaconda和statsmodels的安装,但我没有运气图表,并尝试了几个我通过互联网找到的修复无济于事。

0 个答案:

没有答案