前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用CNN(LSTM架构)进行序列预测基于TensorFlow

使用CNN(LSTM架构)进行序列预测基于TensorFlow

作者头像
量化投资与机器学习微信公众号
发布2018-01-29 17:37:33
2.4K0
发布2018-01-29 17:37:33
举报

作者 / mouradmourafiq

翻译 / 编辑部翻译组

来源 / https://github.com/mouradmourafiq

前言

这篇推文抛砖引玉的介绍如何使用循环神经网络逼近一系列向量,特别的是,将使用LSTM架构。

根据先前的观察预测一系列实数。 传统的神经网络架构不能做到这一点,这就是为什么要复制神经网络来解决这个问题,因为它们允许存储以前的信息来预测将来的事件。

在这个例子中,将尝试预测一些功能:

  • sin
  • sin and cos on the same time
  • x*sin(x)

模型的建立

首先建立模型,lstm_model,该模型是不同时间步骤的堆叠lstm单元的列表,后面是一个密集层。

因此,我们的模型期望一个维度对应的数据((batch size, time_steps of the first lstm cell, num_features in our data)

接下来,我们以模型可以接受的方式准备数据。

这将创建一个数据,这将允许我们的模型查看time_steps在过去的次数,以进行预测。 所以如果我们的第一个单元格是10个time_steps单元格,那么对于我们想做的每个预测,我们需要为单元格提供10个历史数据点。 y值应该对应于我们想要预测的数据的第十个值。

我们首先定义超参数

现在我们可以根据我们的模型创建一个回归函数

预测sin函数

测试集

  • real sin function

一起预测sin和cos函数

测试集

  • predicted sin-cos function

x*sin

  • 真实 x*sin
  • 预测 x*sin

model loss

文档说明

Install and Run

Create a Virtual Environment

It is reccomended that you create a virtualenv for the setup since this example is highly dependant on the versions set in the requirements file.

$ virtualenv ~/python/ltsm
$ source ~/python/ltsm/bin/activate
(ltsm) $

Install Requirements

This example depends on tensorflow-0.11.0 to work. You will first need to install the requirements. You will need the appropriate version of tensorflow for your platform, this example is for mac. For more details goto TAG tensorflow-0.11.0 Setup

(ltsm) $ pip install -U https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py3-none-any.whl
(ltsm) $ pip install -r ./requirements.txt

Running on Jupyter

Three Jupyter notebooks are provided as examples on how to use lstm for predicting shapes. They will be available when you start up Jupyter in the project dir.

(ltsm) $ jupyter notebook

- END -

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-04-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 量化投资与机器学习 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Install and Run
    • Create a Virtual Environment
      • Install Requirements
        • Running on Jupyter
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档