-
Notifications
You must be signed in to change notification settings - Fork 5
MLearn Classification
Classifiers in the MLearn.JS package attempt to identify which of a set of categories new prediction data belongs. Supervised classifiers used a labeled dataset which contains x number of unique targets designated as possible categories.
You can use the mlearn.classifier() method to retrieve a classification model. The below code creates a K-Nearest Neighbors model.
var model = mlearn.classifier('knn', {
neighbors: 5, metric: 'euclidian', weights: true
});The classifier.train() method can be used to train a model. Training a model will prepare it for making predictions.
model.training(X, Y).then(function () {
console.log('I am a trained model!');
});The classifier.predicting() method can be used to retrieve the predicted category of a new feature dataset or single feature row.
model.training(X, Y).then(function () {
model.predicting(P).then(function (predictions) {
predictions.each(function (prediction) {
console.log('I predicted ', prediction);
});
});
});The classifier.scoring() method can be used to make multiple predictions and measure the performance of the classifier.
model.scoring(X, Y).then(function (score) {
// gather some metrics
});The score.accuracy() methods returns the percentage of predictions that were correct.
model.scoring(X, Y).then(function (score) {
console('Accuracy: ', score.accuracy() );
});The score.error() methods returns the percentage of predictions that were incorrect.
model.scoring(X, Y).then(function (score) {
console('Error Rate: ', score.error() );
});The score.misses() methods returns an array of objects containing target and prediction for all invalid predictions made during scoring.
model.scoring(X, Y).then(function (score) {
score.misses().each(function (x) {
console('Predicted: ' + x.prediction + ', Target: ' + x.target);
});
});