“微信公众号”
一、回归预测要实现的问题
这次我们会使用RNN来进行回归(Regression)的训练,使用自己创建的sin曲线预测一条cos曲线。如下图所示,我们用蓝色的sin曲线预测红色的cos曲线。
二、回归预测要实现的效果
经过RNN的回归训练,我们的网络预测结果和真实结果的一个比对图,如下所示。
三、网络结构展示
四、代码展示
#conding:utf-8
'''
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
Run this script on tensorflow r0.10. Errors appear when using lower versions.
'''
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
# define super-parameters
BATCH_START = 0 # 建立batch data时候的index
TIME_STEPS = 20 # backpropagation through time 的 time_steps
BATCH_SIZE = 50
INPUT_SIZE = 1 # sin 数据输入size
OUTPUT_SIZE = 1 # cos数据输出size
CELL_SIZE = 10 # RNN的hidden unit size
LR