ml5js / ml5-library

Friendly machine learning for the web! 🤖
https://ml5js.org
Other
6.48k stars 902 forks source link

Q: How do I add my own data to the KNN classifier? #399

Closed fartass closed 5 years ago

fartass commented 5 years ago

Hi, Im trying to add my own data to the KNN classifier, this is my attempt.

let grid = [
  [1, 2],
  [3, 4]
];
let knnClassifier = ml5.KNNClassifier();

console.log('trying to add to classifier');
addExample('left');

function addExample(label) {
  knnClassifier.addExample(grid, label);
}

Which gives me an error.

The example code you provide saids to:

// Convert poses results to a 2d array [[score0, x0, y0],...,[score16, x16, y16]]
const poseArray = poses[0].pose.keypoints.map(p => [p.score, p.position.x, p.position.y]);

So I figgured it wants an array of some type.

fartass commented 5 years ago

Needed the last vertion, so changing 0.1.3 to 0.3.0 and it works. It plays my game really bad though, I wonder how many examples it needs to play...