【脚本语言系列】关于Python统计分析statsmodel,你需要知道的事
2017-04-26 14:50
1176 查看
如何使用statsmodel
安装statsmodel使用easy_install或pip安装statsmodels
easy_install -U statsmodels pip install -U statsmodels
使用源代码安装statsmodels
最小二乘法拟合
加载数据
import statsmodels.api data = statsmodels.api.datasets.copper.load_pandas()
拟合数据
x, y = data.exog, data.endog fit = statsmodels.api.OLS(y, x).fit()
import statsmodels.api data = statsmodels.api.datasets.copper.load_pandas()
x, y = data.exog, data.endog
fit = statsmodels.api.OLS(y, x).fit()
print "Fit params", fit.params
print "Summary"
print fit.summary()
重采样时间序列数据
创建一个日期时间索引对象
dt_idx = pandas.DatetimeIndex(quotes.date)
创建DataFrame对象
df = pandas.DataFrame(quotes.close, index = dt_idx, columns = [symbol])
重采样
resampled = df.resample('M', how=numpy.mean)
绘图
df.plot() resampled.plot() show()
import pandas
from matplotlib.pyplot import show, legend
from datetime import datetime
from matplotlib import finance
import numpy
start = datetime(2011, 01, 01)
end = datetime(2012, 01, 01)
symbol = "AAPL"
quotes = finance.quotes_historical_yahoo_ochl(symbol, start, end, asobject = True)
dt_idx = pandas.DatetimeIndex(quotes.date)
df = pandas.DataFrame(quotes.close, index = dt_idx, columns = [symbol])
resampled = df.resample('M', how=numpy.mean)
print resampled
df.plot() resampled.plot() show()
什么是statsmodel
statsmodels的发行版有很多的范例数据集。相关文章推荐
- 【脚本语言系列】关于Python网络分析Scapy,你需要知道的事
- 【脚本语言系列】关于Python算法分析,你需要知道的事
- 【脚本语言系列】关于Python性能分析工具timeit, 你需要知道的事
- 【脚本语言系列】关于 Python 数据分析,你需要知道的事
- 【脚本语言系列】关于Python代码分析工具line_profiler,你需要知道的事
- 【脚本语言系列】关于Python邮件服务poplib,你需要知道的事
- 【脚本语言系列】关于PythonGUI界面PyQT,你需要知道的事
- 【脚本语言系列】关于Python网页服务Microsoft IIS,你需要知道的事
- 【脚本语言系列】关于Python测试工具Pylint, 你需要知道的事
- 【脚本语言系列】关于Python测试工具Pyflakes, 你需要知道的事
- 【脚本语言系列】关于Python图像处理scikits-image, 需要知道的事
- 【脚本语言系列】关于Python邮件服务smtplib,你需要知道的事
- 【脚本语言系列】关于Python测试工具unittest, 你需要知道的事
- 【脚本语言系列】关于Python开发环境搭建,你需要知道的事
- 【脚本语言系列】关于Python机器学习scikits-learn,你需要知道的事
- 【脚本语言系列】关于Python图像处理PIL,你需要知道的事
- 【脚本语言系列】关于Python数据库处理MySQL, 你需要知道的事
- 【脚本语言系列】关于Python测试工具lettuce, 你需要知道的事
- 【脚本语言系列】关于Python测试工具mock, 你需要知道的事
- 【脚本语言系列】关于Python数值计算Pandas,你需要知道的事