资源简介
基于Keras的GRU神经网络实现 Python编写 可以直接运行得到结果
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Created on Wed Aug 2 14:19:58 2017
@author: 璐
“““
# -*- coding: utf-8 -*-
“““
Created on Sun Jul 9 18:07:53 2017
@author: 璐
“““
# -*- coding:utf-8 -*-
‘‘‘
We can also phrase the problem so that multiple recent time steps can be
used to make the prediction for the next time step.
This is called a window and the size of the window
is a parameter that can be tuned for each problem.
For example given the current time (t) we want to predict
the value at the next time in the sequence (t+1) we can use the current time (t)
as well as the two prior times (t-1 and t-2) as input variables.
When phrased as a regression problem the input
variables are t-2 t-1 t and the output variable is t+1.
The create_dataset() function we created in the previous section allows
us to create this formulation of the time series problem
by increasing the look_back argument from 1 to 3.d
‘‘‘
#用import或者from import导入相关模块;numpy用来存储和处理大型矩阵
#pandas结构化数据的输入与输出
#import time
import numpy as np
import pandas as pd
import math
#Sequential多个网络层的线性堆叠;Dense隐含层
from keras.models import Sequential
from keras.layers import Dense
#from keras.layers import LSTM
#from keras.layers import SimpleRNN
from keras.layers import GRU
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error mean_absolute_error
#from sklearn.metrics import mean_squared_errormean_absolute_error
#from keras import initializers
# record running time/记录时间
# convert an array of values into a dataset matrix
def create_dataset(dataset look_back):
dataX dataY = [] []
for i in range(len(dataset)-look_back):
a = dataset[i:(i+look_back) 0]
#append向列表的尾部增加元素
dataX.append(a)
dataY.append(dataset[i + look_back 0])
return np.array(dataX) np.array(dataY)
# fix random seed for reproducibility
#seed用于指定随机数生成时所用算法开始的整数值
np.random.seed(7)
# load the dataset/下载数据集
#usecols获取数据的列,如果取前4列,则usecols=(0123)
#print(XXXX)
dataframe = pd.read_csv(r‘nn.csv‘ \
usecols=[0] engine=‘python‘)
dataset = dataframe.values
dataset = dataset.astype(‘float32‘)
# normalize the dataset/标准化数据集
scaler = MinMaxScaler(feature_range=(0 1))
dataset = scaler.fit_transform(dataset)
# split into train and test sets/分割训练集与测试集
#train_size = int(len(dataset) * 0.84)
vsize=18;
train_size = len(dataset)-vsize-18;
#print(train_size )
# test_size = len(dataset) - train_size
look_back =10
train test pred = dataset[0:train_size:] dataset[train_size-look_back:train_size+vsize:] \
dataset[train_size+vsize-look_back:len(dataset):]
# dataset detail/具体分割后数据集
trainX trainY = create_dataset(train look_back)
testX testY = create_dataset(test look_back)
predX predY = create_dataset(pred look_back)
# reshape input to be [samples feature_num features]
trainX = np.reshape(trainX (
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5450 2019-02-21 20:59 GRU\12.xlsx
文件 6028 2019-02-21 21:00 GRU\GRU.py
文件 852 2018-01-28 10:26 GRU\nn.csv
目录 0 2019-02-21 20:59 GRU\
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论