Python 2.7 Python绘图的困难
我对此的看法是:Python 2.7 Python绘图的困难,python-2.7,anaconda,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 =
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');
没有任何图表。有什么东西我忘了或遗漏了吗?目前,我只是尝试测试anaconda和statsmodels的安装,但我对这些图表几乎没有什么运气,并且尝试了几次通过互联网发现的修复,但都无济于事 如果在末尾添加
plt.show()
会发生什么?(这对我来说足够了,但对你来说可能不行,这取决于你的环境。)是的,它没有任何作用。:/我正在使用eclipse。
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]