0

I want to compute the time that a machine learning model takes to process to classify the data. I am using scikit-learn. I can compute the accuracy, the recall and the precision by using:

from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
.....
model.fit(Xtrain, Ytrain)
y_pred = model.predict(Xtest)
print(accuracy_score(Ytest, y_pred))
print(confusion_matrix(Ytest, y_pred))
print(classification_report(Ytest, y_pred))

But I do not know how to compute the evaluation time of the classification. Is there

dina
  • 351
  • 1
  • 3
  • 9
  • 1
    Possible duplicate of [Accurate timing of functions in python](https://stackoverflow.com/questions/889900/accurate-timing-of-functions-in-python) – Jack Moody May 18 '19 at 22:22

2 Answers2

3

Like this:

from time import time

t0 = time()
fit_classifier()
print(time() - t0)
qmeeus
  • 2,341
  • 2
  • 12
  • 21
2

you could simply use something like that:

import time
.....
start = time.time()
y_pred = model.predict(Xtest)
end = time.time()
eval_time = end-start # in seconds

Just wrap the part of code you want to inspect with start = ... and end = ...

pmarcol
  • 453
  • 2
  • 9