Using pd.crosstab, I can produce a confusion matrix from my predicted data. I used the following line to generate the confusion matrix:
pd.crosstab(test_data['class'], test_data['predicted'], margins = True)
Similarly in R, I can generate a confusion matrix using the line below
confusion_matrix <- table(truth = data.test$class, prediction = predict(model, data.test[,-46], type = 'class'))
And in R I can find the accuracy of my model using this line
sum(diag(confusion_matrix)) / sum(confusion_matrix)
In Python, is there an equivalent of sum(diag(confusion_matrix)) / sum(confusion_matrix) to calculate the accuracy from my confusion matrix?
I will prefer not to use any libraries except pandas (e.g Scikit learn).