Hey,
I use a very vanilla ML pipeline. I use the train function made available and its working well. My training function is iterative and thus can be interrupted at any point in time: How can I monitor time used to make sure that I don't overrun the 10min time limit?
Here is the Train call:
self.Train(self.DateRules.Every(DayOfWeek.Sunday), self.TimeRules.At(8 , 0), self.train)
The train function:
def train(self):
keep_training = 1
while keep_training:
#Train function call
#...
#check time spent ??? How???
#Update keep_training
I tried with a straightforward datetime delta but it doesn't seem to work:
def train(self):
start_time = datetime.now()
keep_training = 1
while keep_training:
#Train function call
#...
#time delta
train_time = datetime.now() - start_time
#Update keep_training
if train_time >= datetime.delta(minutes=9):
keep_training = 0
Thank you for any pointers or suggestions!
Rahul Chowdhury
Hi Louis,
You can use the self.Train method to train your model. Within self.Train, the normal 10 minute time limit is increased with time taken from a 30 minute "reservoir", allowing you more time to train your models. You can learn more about training ML models in the documentation.
Best
Rahul
Louis Gobin
Thank you Rahul,
I am using the train method (great feature btw, thanks) and it's very practical. Is there a way to monitor time use by a function? Be it train or another function to ensure that they do not pass whatever time limit I want to put on them?
Best,
Louis
Derek Melchin
Hi Louis Gobin,
We can limit the duration of a function’s execution by returning from the function after a specified time interval has passed. The code below will return to the caller after it has been executing for at least `self.max_train_seconds`.
def train(self): start_time = datetime.now() # Current time while True: # Train function call... # Stop looping if reached maximum training duration if (datetime.now() - start_time).seconds >= self.max_train_seconds: break
This function can be adjusted to apply a threshold based on minutes by replacing the seconds attribute with minutes. Note that if we want the function to take no longer than 10 minutes, we should place the threshold just below 10 minutes as the break condition checks whether the max train duration has been reached.
See the attached backtest for a full working example.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Louis Gobin
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!