etai83 / lstm_stock_prediction Goto Github PK
View Code? Open in Web Editor NEWThis is an LSTM stock prediction using Tensorflow with Keras on top.
This is an LSTM stock prediction using Tensorflow with Keras on top.
I know that model.predict in this case needs to have three dimensions, but how can I forecast the future with only "dates" or the x axis?
The prediction model always forms a straight line
Why do you split that data twice? You do it first manually in loaddata() then you do it again when you fit the model using validation_split = 0.1 , you could use validation_data= (x_test, y_test) instead. This appears to skew the results and you lose the important data which is the most recent points.
Hi etai83,
Thank you very much for your code, i'm learning neural network coding and this was pretty interesting.
I'm trying to increase the number of data points in the raw csv, with the same format as before but i'm getting an error. The only difference is that the number of rows in the url's output csv goes to 730.
Can you tell me what am I doing wrong?
Error:
Traceback (most recent call last):
File "/home/lucardi/Downloads/Python/prediction.py", line 47, in <module>
df['Open'] = df['Open'] / 100
File "/usr/local/lib/python3.5/dist-packages/pandas/core/ops.py", line 721, in wrapper
result = wrap_results(safe_na_op(lvalues, rvalues))
File "/usr/local/lib/python3.5/dist-packages/pandas/core/ops.py", line 692, in safe_na_op
lambda x: op(x, rvalues))
File "pandas/_libs/algos_common_helper.pxi", line 1212, in pandas._libs.algos.arrmap_object (pandas/_libs/algos.c:31954)
File "/usr/local/lib/python3.5/dist-packages/pandas/core/ops.py", line 692, in <lambda>
lambda x: op(x, rvalues))
TypeError: unsupported operand type(s) for /: 'str' and 'int'
Code:
def get_stock_data(stock_name, normalized=0):
url="https://www.google.com/finance/historical?cid=12607212&startdate=Jun+27%2C+2014&enddate=Jun+26%2C+2017&num=30&ei=JohRWYGFKMSde-zRjugB&output=csv"
col_names = ['Date','Open','High','Low','Close','Volume']
stocks = pd.read_csv(url, header=0, names=col_names)
df = pd.DataFrame(stocks)
date_split = df['Date'].str.split('-').str
df['Year'], df['Month'], df['Day'] = date_split
df["Volume"] = df["Volume"] / 1000
df["Close"] = df["Close"] / 1000
df["High"] = df["High"] / 1000
df.drop(df.columns[[0,3,5,6, 7,8]], axis=1, inplace=True)
return df
First of all, thanks so much for this code. It has been fun for me to try and understand and work with to familiarize myself with these concepts.
I am having an issue with this workbook though. I am always getting a straight line for my predictions in the final graph.
Is it possible that I am running the wrong version of Keras or one of the other dependencies? if so, do you have any idea what versions you were running?
Any guidance would be greatly appreciated.
Thanks very much.
Hi, Thank you for sharing this code. I am have been using this code to learn about machine learning, by trying to predict Bitcoin values. I noticed that the test data (y_test) start from the beginning of the dataset at line. X_train, y_train, X_test, y_test = load_data(df[::-1], window). Any particular reason for that?
hi, the stock data would be different while running this code on different date? and the value of prediction should be same single value strangely? what's more, the train score:2.83 MSE(1.68 RMSE) and test score:1.22 MSE(1.10 RMSE) are not just like 0.08MSE(0,29RMSE) and 0.04MSE(0,20RMSE). Thanks a lot.
Hello Community,
I was able to test this program, even I needed to get the CSV from somewhere else.
However I do not realy understand nor I cannot find the the relevant parts within the program which tells me how far each prediction on the graph is ahead of the knowlage it has about the priceline.
I would be very happy if someone could guid me .
THX!!!
what is the use of the second square bracket?---> [:, -1]
Hi, just reading your codes. It seems like the load_data function is predicting day 1 (in y test) by using day 2 to day 6 (in x test). Just wondering the right method should be predicting day 6 closing price by using day 1 to day 5? Thanks
Hi,
Iv'e altered your code to support google API instead of yahoo which stopped working
but the prediction seems to always return 0, even the acc prints always 0,
can you please explain why?
Where can I find size of timestep?
The yahoo finance URL referenced here appears to be dead.
http://chart.finance.yahoo.com/table.csv?s=GOOGL&a=11&b=15&c=2011&d=29&e=10&f=2016&g=d&ignore=.csv
Using your latest code, the prediction is a straight line.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.