huseinzol05 / Stock-Prediction-Models

Gathers machine learning and deep learning models for Stock forecasting including trading bots and simulations
Apache License 2.0
7.69k stars 2.74k forks source link

Live Agent - app.py says there is no model.pkl #41

Closed augmen closed 4 years ago

augmen commented 5 years ago

Questions on live agent - after running this command python3 app.py generates error there is no

model.pkl file

?

plz guide how to solve it . As i try to run the realtime-evolution-stratgegy.py so to save model.pkl and then app.py but doesn't work the either way . @plz guide.

huseinzol05 commented 5 years ago

If you follow agent.ipynb, at the end of it,

import pickle

with open('agent.pkl', 'wb') as fopen:
    pickle.dump(agent, fopen)

It will save the model as pickle and reload it inside app.py.

I will push my pickled later, but it is not perfect. It is better if you train it again.

augmen commented 5 years ago

it saves as agent.pkl not model.pkl . the function ask as model.pkl.

augmen commented 5 years ago

How the systems exactly works : I need to train my model with agent.py then dump model with pickle to agent.pkl / model.pkl then load that model with app.py and connect to websocket live data for real time prices and trade details ? Right . Then whats the use of realtime-strategy.ipynb file ? I found it can trade between multiple stiock options ? Right ?

Can you guide me more websocket integration on live trading :) which would be the ideal file to integration and how to do it ? Plz guide @huseinzol05 .

augmen commented 5 years ago

if you run app.py it states :

Traceback (most recent call last): File "app.py", line 344, in <module> with open('model.pkl', 'rb') as fopen: FileNotFoundError: [Errno 2] No such file or directory: 'model.pkl'

in app.py the pickle function is like below 👍 with open('model.pkl', 'rb') as fopen: model = pickle.load(fopen)

in realtime strategy.ipynb the pickle function is like below 👍 👍 import copy import pickle

copy_model = copy.deepcopy(agent.model)

pickle.dump(copy_model, 'model.pkl', 'rb')`

if you change the model.pkl with agent.pkl in app.py it generates error on

model.get_rewrds function ?

Traceback (most recent call last): File "app.py", line 359, in <module> minmax = minmax) File "app.py", line 135, in __init__ self.model.get_weights(), AttributeError: 'Agent' object has no attribute 'get_weights'

so it is better to ask the creator @huseinzol05 Plz guide

:)

augmen commented 5 years ago

@huseinzol05 the agent.py file dump agent.pkl and realtime strategy dump model.pkl

augmen commented 5 years ago

@huseinzol05 got success in saving model.pkl . plz answer in app.py after importing model.pkl as we don'tneed flask server i have removed the false code. which function should we initiative to start the buy and sell . is it def buy agent.buy() or def trade agent.trade(data) ? As i have tried with both the but, the app.py file dosent started ?

augmen commented 4 years ago

@huseinzol05 @huseinzol05 i understand that we can connect the web sockets using request.ipynb flow live data to the app.py . then why there is line 347 app.py we have :

df = pd.read_csv('TWTR.csv') real_trend = df['Close'].tolist() parameters = [df['Close'].tolist(), df['Volume'].tolist()] minmax = MinMaxScaler(feature_range = (100, 200)).fit(np.array(parameters).T) scaled_parameters = minmax.transform(np.array(parameters).T).T.tolist() initial_money = np.max(parameters[0]) * 2

why we need to feed again this data in app.py ?

augmen commented 4 years ago

If you follow agent.ipynb, at the end of it,

import pickle

with open('agent.pkl', 'wb') as fopen:
    pickle.dump(agent, fopen)

It will save the model as pickle and reload it inside app.py.

I will push my pickled later, but it is not perfect. It is better if you train it again.

augmen commented 4 years ago

@huseinzol05 @huseinzol05 i understand that we can connect the web sockets using request.ipynb flow live data to the app.py . then why there is line 347 app.py we have :

df = pd.read_csv('TWTR.csv') real_trend = df['Close'].tolist() parameters = [df['Close'].tolist(), df['Volume'].tolist()] minmax = MinMaxScaler(feature_range = (100, 200)).fit(np.array(parameters).T) scaled_parameters = minmax.transform(np.array(parameters).T).T.tolist() initial_money = np.max(parameters[0]) * 2 why we need to feed again this data in app.py ?

huseinzol05 commented 4 years ago

Because that are parameters needed by the model. I think you can try to improve the code and send a pull request, my code seems sucks.

augmen commented 4 years ago

How to accelerate training with big data and more epochs ? will you add GPU support, as official Scikit says no GPU support. can you add some code to accelerate training with big data or some code version with pytorch ? or rapid library or cython.@huseinzol05

augmen commented 4 years ago

@huseinzol05 can we use Rapids.ai to accelerate the training

huseinzol05 commented 4 years ago

Fixed, added model.pkl