资源简介
基于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\
相关资源
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
评论
共有 条评论