资源简介
采用LSTM循环神经网络对时序数据进行预测,根据评价指标对测试集进行误差计算,具有较好的预测精度
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Created on Fri Nov 17 11:09:14 2017
@author: Administrator
“““
import time
import numpy
from math import sqrt
from numpy import concatenate
from matplotlib import pyplot
from pandas import read_csv
from pandas import Dataframe
from pandas import concat
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import mean_squared_error
from keras.models import Sequential
from keras.layers import DenseActivationdropout
from keras.layers import LSTM
# convert series to supervised learning 将序列转换成监督学习问题
def series_to_supervised(data n_in=1 n_out=1 dropnan=True):
n_vars = 1 if type(data) is list else data.shape[1]
df = Dataframe(data)
cols names = list() list()
# input sequence (t-n ... t-1)
for i in range(n_in 0 -1):
cols.append(df.shift(i))
names += [(‘var%d(t-%d)‘ % (j + 1 i)) for j in range(n_vars)]
# forecast sequence (t t+1 ... t+n)
for i in range(0 n_out):
cols.append(df.shift(-i))
if i == 0:
names += [(‘var%d(t)‘ % (j + 1)) for j in range(n_vars)]
else:
names += [(‘var%d(t+%d)‘ % (j + 1 i)) for j in range(n_vars)]
# put it all together
agg = concat(cols axis=1)
agg.columns = names
# drop rows with NaN values
if dropnan:
agg.dropna(inplace=True)
return agg
# load dataset
dataset = read_csv(‘tuoluoyi-A-kewen1-csv.csv‘ header=0 index_col=0) #header 第一列为编号 index_col为取索引的参数
values = dataset.values
pyplot.figure(1)
pyplot.plot(values)
pyplot.show()
# integer encode direction
#encoder = LabelEncoder() #简单来说 LabelEncoder 是对不连续的数字或者文本进行编号
#values[: 4] = encoder.fit_transform(values[: 4]) #将第四列进行文本编码
# ensure all data is float
values = values.astype(‘float32‘) #转化为浮点型
# normalize features
scaler = MinMaxScaler(feature_range=(0 1)) #归一化处理
scaled = scaler.fit_transform(values)
# frame as supervised learning
reframed = series_to_supervised(scaled 1 1) #转化为监督学习 设计预测维数
# drop columns we don‘t want to predict
#reframed.drop(reframed.columns[[567]] axis=1 inplace=True) #reframed.drop 删除不预测的列
print(reframed.head())
# split into train and test sets
values = reframed.values
n_train_hours = 41000
train = values[:n_train_hours :]
test = values[n_train_hours: :]
# split into input and outputs
train_X train_y = train[: :-1]
- 上一篇:python词云源码
- 下一篇:python腾讯文字识别 OCR脚本
相关资源
- 运用LSTM对CPI数据进行预测.py
- Long Short-Term Memory Networks With Python
- MLP/RNN/LSTM模型进行IMDb情感分析
- Introduction to time series.pdf + Deep Time Se
- 时间序列预测讲义ARIMA&LSTM;及python代码
- Python-一个非常简单的BiLSTMCRF模型用于
- LSTM模型学习
- LSTM数据集+python源码
- PSO-LSTM.py
- 15.时间序列预测LSTM模型python代码实现
- LSTM预测股价代码
- LSTM股价预测(python).zip
- LSTM可以运行
- LSTM时间序列预测销量
- 基于lstm的语义相似度计算模型代码
- 使用LSTM进行时间序列预测
- lstm_attention文本分类代码
- 基于LSTM的RNN网络人体骨骼关节点检测
- 时间长短序列网络LSTM
- Tensorflow-BiLSTM分类
- keras上LSTM长短期记忆网络金融时序预
- 基于LSTM的航班乘客预测
- lstm_tensorflow
- LSTM股票预测
- lstm情感分析代码
- tensorflow下用LSTM网络进行时间序列预测
- 股票预测 LSTM 时间序列rnn 代码程序数
- LSTMLong Short-Term Memory长短期记忆网络
- 卷积LSTM代码
- LSTM上证指数收盘价预测.zip
评论
共有 条评论