python编程实用链接

来源:互联网 发布:知秋作品 编辑:程序博客网 时间:2024/06/06 15:40

链接:

http://www.36dsj.com/archives/44065 时间序列预测全攻略

http://blog.csdn.net/zutsoft/article/details/51483710 【pandas】[2] DataFrame 基础,创建DataFrame和增删改查基本操作(1)

http://blog.csdn.net/roamer314/article/details/52179191 Pandas的 loc iloc ix区别

http://blog.csdn.net/jinruoyanxu/article/details/53390943   python画分布、密度等图形

http://blog.csdn.net/u014356002/article/details/53163684 时间序列(arima)+支持向量机(svm)+优化=组合预测

https://stackoverflow.com/questions/22770352/auto-arima-equivalent-for-python auto.arima() equivalent for python

http://blog.csdn.net/u010414589/article/details/49622625   [python]时间序列分析之ARIMA

http://chuansong.me/n/523863947271 时间序列ARIMA模型详解:python实现店铺一周销售量预测

http://www.cnblogs.com/zhusleep/p/5616099.html  Anaconda安装更新库

http://www.tuicool.com/articles/yIRfIv7 使用时间序列预测网站流量增长趋势(ARIMA)

http://blog.csdn.net/net_wolf_007/article/details/51726480  numpy.array操作简单总结

http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVR.html  sklearn.svm.SVR

http://blog.csdn.net/zhuxiaodong030/article/details/54316345  pandas常用函数

# print('预测值和真实值对比:使用固定训练集连续预测50个数据')
# history=train
# predictions1 = list()  # 预测值1列表
# confidence_intervals1 = list()  # 置信区间1列表
# for t in range(len(test)):
#     model1 = ARIMA(history,order=pdq).fit()
#     output1 =model1.forecast(steps=1)  # 预测下一个值
#     # forecast返回值为有3个元素的元组(tuple),每个元素都是一个array,说明:forecast : array, stderr : array,conf_int : array2D
#     # 因为元组不允许修改,因此将预测值和标准差单独存储到list中
#    predictions1.append(float(output1[0])) # 将预测值加入预测结果
#    confidence_intervals1.append(output1[2]) # 将置信区间加入预测结果
#     history =history.append(pd.Series(output1[0], index=[test.index[t]]))  # train数据增加一个
#     # print('predicted=%f, expected=%f'% (np.exp(output2[0]), np.exp(test[t]))) #不打印中间结果
# mse = mean_squared_error(test, predictions1)
# print('测试均方根误差: %.6f' % mse)

# print('预测值和真实值对比:不段填充训练集每次预测1个值,循环预测50个数据')
# history=train
# predictions2 = list()  # 预测值2列表
# confidence_intervals2 = list()  # 置信区间2列表
# for t in range(len(test)):
#     model2 = ARIMA(history,order=pdq).fit()
#     output2 = model2.forecast(steps=1)  # 预测下一个值
#     # forecast返回值为有3个元素的元组(tuple),每个元素都是一个array,说明:forecast : array, stderr : array,conf_int : array2D
#     # 因为元组不允许修改,因此将预测值和标准差单独存储到list中
#    predictions2.append(float(output2[0])) # 将预测值加入预测结果
#     confidence_intervals2.append(output2[2])  # 将置信区间加入预测结果
#     history =history.append(pd.Series([test[t]], index=[test.index[t]]))  # train数据增加一个
#     # print('predicted=%f, expected=%f'% (np.exp(output2[0]), np.exp(test[t]))) #不打印中间结果
# mse = mean_squared_error(test, predictions2)
# print('测试均方根误差: %.6f' % mse)

 

 

import pandas as pdimport numpy as npimport matplotlib.pyplot as pltfrom statsmodels.tsa.stattools import adfuller  # 导入ADF检验函数from statsmodels.tsa.seasonal import seasonal_decompose  # 导入季节性分解函数,将数列分解为趋势、季节性和残差三部分from statsmodels.stats.diagnostic import acorr_ljungbox  # 导入白噪声检验函数from statsmodels.graphics.tsaplots import plot_pacf, plot_acf  # 导入自相关和偏自相关的绘图函数from matplotlib.ticker import MaxNLocator  # 导入自动查找到最佳的最大刻度函数from statsmodels.tsa.arima_model import ARIMA  # 导入ARIMA模型from sklearn.metrics import mean_squared_errorimport statsmodels.api as smimport datetime as dt# 欧元汇率预测df_fx_data = pd.read_csv('D:\\BOE-XUDLERD.csv'# 读取数据集df_fx_data['Date'] = pd.to_datetime(df_fx_data['Date'])  # Date列转换为日期型indexed_df = df_fx_data.set_index('Date'# 将日期设置为索引ts = indexed_df['Value'# 将DataFrame切片为一维Series,Series包含日期索引ts_week = ts.resample('W').mean()ts_week= ts_week.diff(1)#我们已经知道要使用一阶差分的时间序列,之前判断差分的程序可以注释掉arma_mod = sm.tsa.ARMA(ts_week.dropna(),(2,2)).fit()predict_sunspots = arma_mod.predict(2213, 2263, dynamic=True)fig, ax = plt.subplots(figsize=(12, 8))ax = ts_week.ix[2100:].plot(ax=ax)predict_sunspots.plot(ax=ax)plt.show()print('end')dta=[10930,10318,10595,10972,7706,6756,9092,10551,9722,10913,11151,8186,6422,6337,11649,11652,10310,12043,7937,6476,9662,9570,9981,9331,9449,6773,6304,9355,10477,10148,10395,11261,8713,7299,10424,10795,11069,11602,11427,9095,7707,10767,12136,12812,12006,12528,10329,7818,11719,11683,12603,11495,13670,11337,10232,13261,13230,15535,16837,19598,14823,11622,19391,18177,19994,14723,15694,13248,9543,12872,13101,15053,12619,13749,10228,9725,14729,12518,14564,15085,14722,11999,9390,13481,14795,15845,15271,14686,11054,10395]dta=pd.Series(dta)dta.index = pd.Index(sm.tsa.datetools.dates_from_range('2001','2090'))dta.plot(figsize=(12,8))print(help(sm.tsa.ARMA))dta= dta.diff(1)#我们已经知道要使用一阶差分的时间序列,之前判断差分的程序可以注释掉arma_mod20 = sm.tsa.ARMA(dta.dropna(),(7,1)).fit()predict_sunspots = arma_mod20.predict('2090', '2100', dynamic=True)print(predict_sunspots)fig, ax = plt.subplots(figsize=(12, 8))ax = dta.ix['2001':].plot(ax=ax)predict_sunspots.plot(ax=ax)plt.show()print('end')

 

原创粉丝点击