"compute confusion matrix using python" Code Answer's
You're definitely familiar with the best coding language Python that developers use to develop their projects and they get all their queries like "compute confusion matrix using python" answered properly. Developers are finding an appropriate answer about compute confusion matrix using python related to the Python coding language. By visiting this online portal developers get answers concerning Python codes question like compute confusion matrix using python. Enter your desired code related query in the search bar and get every piece of information about Python code related question on compute confusion matrix using python.
compute confusion matrix using python
import numpy as np
currentDataClass = [1, 3, 3, 2, 5, 5, 3, 2, 1, 4, 3, 2, 1, 1, 2]
predictedClass = [1, 2, 3, 4, 2, 3, 3, 2, 1, 2, 3, 1, 5, 1, 1]
def comp_confmat(actual, predicted):
classes = np.unique(actual) # extract the different classes
matrix = np.zeros((len(classes), len(classes))) # initialize the confusion matrix with zeros
for i in range(len(classes)):
for j in range(len(classes)):
matrix[i, j] = np.sum((actual == classes[i]) & (predicted == classes[j]))
return matrix
comp_confmat(currentDataClass, predictedClass)
array([[3., 0., 0., 0., 1.],
[2., 1., 0., 1., 0.],
[0., 1., 3., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 1., 1., 0., 0.]])
Source: stackoverflow.com
All those coders who are working on the Python based application and are stuck on compute confusion matrix using python can get a collection of related answers to their query. Programmers need to enter their query on compute confusion matrix using python related to Python code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about compute confusion matrix using python for the programmers working on Python code while coding their module. Coders are also allowed to rectify already present answers of compute confusion matrix using python while working on the Python language code. Developers can add up suggestions if they deem fit any other answer relating to "compute confusion matrix using python". Visit this developer's friendly online web community, CodeProZone, and get your queries like compute confusion matrix using python resolved professionally and stay updated to the latest Python updates.