# How to calculate the model building and predicting time of a classifier in python?

#1

I am currently solving one classification problem using naive Bayes algorithm in python, I have built the model, but I want to how to calculate the model building and predicting the time of a model.

``````from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score
import numpy as np
clf = GaussianNB() # gaussian model
clf.fit(features_train,labels_train) # model building
ypred=clf.predict(features_test) #predicting on test data
x=accuracy_score(labels_test, ypred) # accuracy of a model
print(x)``````

#2

@hinduja1234 - You can use time function of a python to calculate the model building and model predicting time.

The code would be like

``````from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
t0=time()
clf.fit(features_train,labels_train)
print "training time:", round(time()-t0, 3), "s" # the time would be round to 3 decimal in seconds
t1=time()
ypred=clf.predict(features_test)
print "predict time:", round(time()-t1, 3), "s"
x=accuracy_score(labels_test, ypred)
print(x)
``````

Hope this helps!

Regards,
Harry