I have understand the model running, I want to know how to save the model which is trained and use the model for testing on another Dataset in Reinfrocement Learning in Trading.
Hello Himanshu,
We're glad to know you are studying the course.
In order to help you, could you please be more specific about what section and unit you're talking about?
Thanks
Jose Carlos
I am using like Run method for training the bot it has experience replay and q , r model. Which model I have to save in order to reuse? and how to resuse?
Hello Himanshu,
I'd like to ask you: Do you mean 'Run' method as we have it in the 'Backtesting Implementation' Section Unit 1?
You're asking: How could you make that backtesting implementation save it and reload whenever you need it?
Is that your question?
Thanks
Hello Jose,
Yes, I am asking the same.
I want to save the trained model. and use when ever I need.
Also it's automatically running for one epoch. How can I run for multiple epoch.
Hi Himanshu,
In Section 22, Unit 3, we have shown how to save trained weights, trade logs and replay buffer. You can check the end of code line 9. Here is the code for saving your trained agent:
r_network.save_weights(rl_config['WEIGHTS_FILE'], overwrite=True)
trade_logs.to_pickle(rl_config['TRADE_FILE'])
pickle.dump(exp_replay.memory, open(rl_config['REPLAY_FILE'], 'wb'))
Note that these rl_config['…_FILE'] are paths+file names. You can see that in the next cell.
Also, in Unit 6 of the same section, there is another code file that shows how you can compare different agents by loading their saved trade logs.
Regarding the multiple epoch part, you can check your other query:
How to train for multiple epochs? And how to reduce learning time - AI & Machine learning - Quantra Community
Hope this helps.
Hi Himanshu have you find out? Funny why is always get code from internet how to save… keep touch in discord : johanB#6530
Hi Himanshu,
So Show how to load model. Where the take 5 hour and can´t see some file is savet in folder or outside they folders.
Hi Johan,
To load a pre-existing model, you must set the "PRELOAD" parameter to "True" in the rl_config dictionary. Now when the "PRELOAD" is set to True, there are two files which are required by the program ("WEIGHTS_FILE" and "REPLAY_FILE") as shown in the image below.
You can find the above code in the quantra_reinforcement_learning.py file.
The file location for these two files should be kept the same as defined in the rl_config dictionary (i.e. inside the data_modules folder). If the above two conditions are taken care of you will be able to preload your model and run it successfully without any errors. However, please feel free to reach out if there are any errors or issues.
Thanks,
Akshay
Hello Himanshu,
Here you have a link in which you could find a solution to your query. The code shows not only how to save a model, but also how to load it.
I hope that helps.
Thanks
Jose Carlos