I Want To Eavalute The Time Needed To Perform Prediction Using A Trained Model
I know timeit can be used to measure the elapsed time, but I don't how to implement in my code. For example, I will evaluate the model performance as follows: scores = model.evalua
Solution 1:
Here is a basic setup:
import time
start_time = time.time()
# code
print("time - {}".format(time.time()-start_time))
You can also make use of Python's function wrappers, and make a wrapper to time your functions. eg.
import time
def getime(func):
def func_wrapper(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
print("function {} completed in - {} seconds".format(
func.__name__,
time.time()-start_time))
return func_wrapper
# ------------ test example of wrapper --------- #
@getime
def foo():
for i in range(1000):
for j in range(2000):
pass
foo()
Output:
function foo completed in - 0.13300752639770508 seconds
Solution 2:
Try:
import time
...
t = time.time()
scores = model.evaluate(X_test, Y_test, verbose=0)
elapsed_time = time.time()-t
To check it 10000 times (for more accurateness), try:
def check():
t = time.time()
scores = model.evaluate(X_test, Y_test, verbose=0)
elapsed_time = time.time()-t
return elapsed_time
average_elapsed_time = [sum(check() for i in range(10000))/10000][0]
Post a Comment for "I Want To Eavalute The Time Needed To Perform Prediction Using A Trained Model"