资源简介
本工程为基于TensorFlow实现的以多维特征作为输入且输出同样为多维的RNN(LSTM)模型。
代码片段和文件信息
#coding=utf-8
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import itertools
import csv
def sub_list(list1list2):
num1 = len(list1)
num2 = len(list2)
list3 = []
if num1 == num2:
for i in range(num1):
list3.append((list1[i]) - int(list2[i]))
return list3
else:
print(‘列表1长度 =‘ num1)
print(‘列表2长度 =‘ num2)
print(‘列表长度不相同,无法相加‘)
return -1
#获取训练集
def get_train_data(batch_size=60time_step=20train_begin=0train_end=90):
batch_index=[]
data_train=data[train_begin:train_end]
#normalized_train_data=(data_train-np.mean(data_trainaxis=0))/np.std(data_trainaxis=0) #标准化
normalized_train_data=data_train
train_xtrain_y=[][] #训练集
for i in range(len(normalized_train_data)-time_step):
if i % batch_size==0:
batch_index.append(i)
x=normalized_train_data[i:i+time_step:input_size]
y=normalized_train_data[i:i+time_stepinput_size:]
train_x.append(x.tolist())
train_y.append(y.tolist())
batch_index.append((len(normalized_train_data)-time_step))
return batch_indextrain_xtrain_y
#获取测试集
def get_test_data(time_step=20test_begin=5800):
print(‘time_step is ‘ time_step)
print(‘train_end is ‘ train_end)
data_test=data[train_end:]
normalized_test_data = data_test
print(‘normalized_test_data len is‘len(normalized_test_data))
#mean=np.mean(data_testaxis=0)
#std=np.std(data_testaxis=0)
#normalized_test_data=(data_test-mean)/std #标准化
size=(len(normalized_test_data)+time_step-1)//time_step #有size个sample
print(‘size is ‘ size)
test_xtest_y=[][]
for i in range(size-1):
x=normalized_test_data[i*time_step:(i+1)*time_step:input_size]
y=normalized_test_data[i*time_step:(i+1)*time_stepinput_size:]
test_x.append(x.tolist())
test_y.extend(y.tolist())
test_x.append((normalized_test_data[(i+1)*time_step::input_size:]).tolist())
test_y.extend((normalized_test_data[(i+1)*time_step:input_size:]).tolist())
‘‘‘
print(‘test_x len is‘len(test_x))
print(‘test_x[7] len is‘len(test_x[7]))
print(‘test_x[0][0] len is‘ len(test_x[0][0]))
print(‘test_y len is‘len(test_y))
print(‘test_y[0] len is‘ len(test_y[0]))
print(‘len(test_y)/output_size is ‘len(test_y)/output_size)
print(test_y)
exit()
‘‘‘
#return meanstdtest_xtest_y
return test_x test_y
# ——————————————————定义神经网络变量——————————————————
def lstm(X):
batch_size = tf.shape(X)[0]
time_step = tf.shape(X)[1]
w_in = weights[‘in‘]
b_in = biases[‘in‘]
input = tf.reshape(X [-1 input_size]) # 需要将tensor转成2维进行计算,计算后的结果作为隐藏层的输入
input_rnn = tf.matmul(input w_in) + b_in
input_rnn = tf.reshape(input_rnn [-1 time_step rnn_unit]) # 将tensor转成3维,作为lstm cell的输入
cell = tf.nn.rn
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 463838 2018-08-03 15:41 TF_RNN(LSTM)\data.csv
文件 12216 2018-08-03 15:30 TF_RNN(LSTM)\readme_lyy.docx
文件 9975 2018-08-03 15:43 TF_RNN(LSTM)\RNN.py
目录 0 2018-08-03 15:44 TF_RNN(LSTM)
----------- --------- ---------- ----- ----
486029 4
相关资源
- 深度学习之TensorFlow 入门、原理与进阶
- Thaiphoon Burner 13.4.0.0 build 0519
- 2015_MLDN_mybatis_hibernate_springmvc_等视频
- 《21个项目玩转深度学习:基于Tenso
- windows+TensorFlow+mask R-CNN
- tensorflow训练CIFAR-10数据集源代码
- Hands-On Machine Learning with Scikit-Learn an
- Bundle Adjustment —A Modern Synthesis
- LearningWebRTC
- tensorflow 五种花朵分类识别
- Hibernate_Struts2_学生选课系统完整版系
- FOCAS2/Ethernet for Linux
- 强化学习精要:核心算法与TensorFlow实
- wininetForNet源代码
- vgg19网络模型百度云npy和mat格式各一份
- 实战Docker到Kubernetes技术系列视频教程
- summernote完整资源包(font、lang、plug
- struts工作原理图、spring框架结构图、
- Struts2+Hibernate实现的一个留言程序
- TMS320C6416 烧写程序及工具
-
fr
ameparser - kubernetes v1.13.1 images 离线镜像包
- 角点检测Corners代码
- code for Large Scale Metric Learning from Equi
- windows7下Lua的编译,使用Visual Studio
- Pattern Classification 2nd edition出版前版本
- 语义图像分割 deeplab-v3 tensorflow 源代码
- hibernate_day02笔记
- 《Quaternions》四元数,作者Ken Shoemak
- 山石防火墙模拟器
评论
共有 条评论