Git Product home page Git Product logo

lstm-predict's Introduction

LSTM_Predict

LSTM使用的是keras所提供的LSTM,而資料前處理則是使用基本的pandas和numpy,同時使用了sklearn的正規化前處理,最後透過matplotlib來視覺化。

  1. 首先建立訓練資料集(15行~33行),並且正規化,將開盤價(open)限縮在0-1之間
  2. 搭建LSTM layer,(40行~55行),每層LSTM配合dropout = 0.2,來避免過擬和(overfitting),最後使用兩層不同數目的全連接層來得到預測股價
  3. 最後透過測試資料集來比對最後數據是否能預測正確(57行~79行),並透過視覺化套件來判斷

程式成果: 藍線是預測股價,紅線是正確答案,整體的預測趨勢都會比較晚個幾天,這是因為timestep我設定比較大的緣故,且都會比正確答案晚個幾天,之後或許可以透過調整參數來改善預測成果。

像是

  • 時間框架長度的調整
  • Keras 模型裡全連結層的 activation 與 optimizaer 的調整
  • Keras 模型用不同的神經網路(種類、順序、數量)來組合
  • batch_size 的調整、epochs 的調整 predict result

參考資料

(詳細作法程式跟網站中都有註解)

  1. https://ithelp.ithome.com.tw/articles/10206312
  2. https://www.finlab.tw/%E7%94%A8%E6%B7%B1%E5%BA%A6%E5%AD%B8%E7%BF%92%E5%B9%AB%E4%BD%A0%E8%A7%A3%E6%9E%90K%E7%B7%9A%E5%9C%96%EF%BC%81/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.