Accuracy of a classification model

To determine how well a classification model is performing we count the number of correctly labeled classes and divide by the number of classes in total. The accuracy is thus given by $$ \begin{align} a(y, \hat{y}) = \frac{1}{n}\sum_{i = 1}^{n} I(y_i = \hat{y}_i), \tag{7} \end{align} $$

where \( I(y_i = \hat{y}_i) \) is the indicator function given by $$ \begin{align} I(x = y) = \begin{array}{cc} 1 & x = y, \\ 0 & x \neq y. \end{array} \tag{8} \end{align}$$

This is the accuracy provided by Scikit-learn when using sklearn.metrics.accuracyscore.

Below we compute the accuracy of the best fit model on the training data (which should give a good accuracy), the test data (which has not been shown to the model) and the critical data (completely new data that needs to be extrapolated).

train_accuracy = skm.accuracy_score(y_train, clf.predict(X_train))
test_accuracy = skm.accuracy_score(y_test, clf.predict(X_test))
critical_accuracy = skm.accuracy_score(labels[critical], clf.predict(data[critical]))

print ("Accuracy on train data: {0}".format(train_accuracy))
print ("Accuracy on test data: {0}".format(test_accuracy))
print ("Accuracy on critical data: {0}".format(critical_accuracy))

We can see that we get quite good accuracy on the training data, but gradually worsening accuracy on the test and critical data.