'how to generate classification report using javascript
I'm using ml5 for a classification problem and I'm applying KNN classifier. How do I get the accuracy and the classification report of the model?
Solution 1:[1]
Notice the documentation mentions this about classify()'s output:
Object: It returns an object with a top classIndex and label, confidences mapping all class indices to their confidence, and confidencesByLabel mapping all classes' confidence by label.
Bellow there are examples as well, such as the ml5/p5/KNNClassification_Video example.
If you print the result in gotResults() you'll see something like this:
{
"classIndex": 2,
"label": "Scissor",
"confidences": {
"0": 0.3333333333333333,
"1": 0,
"2": 0.6666666666666666
},
"confidencesByLabel": {
"Rock": 0.3333333333333333,
"Paper": 0,
"Scissor": 0.6666666666666666
}
}
classIndexwill be the index of the top classlabelis the string associated with that classconfidencesreturns object where the key is the class index and the value is the confidence (as a normalised value (e.g. 0.0 = 0%, 0.5 = 50%, 1.0 = 100%, etc.)confidencesByLabelprovides the same confidence values as above, but instead of the class indices the keys are the class labels.
In short, once you call classify(), in the result handler, you're after result.confidences or result.confidencesByLabel depending on your application.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | George Profenza |
