mlhelper icon indicating copy to clipboard operation
mlhelper copied to clipboard

inx values

Open waltergms opened this issue 7 years ago • 1 comments

I belive that it is not a bug, but i want to draw the results and dont know what should go on inx values...

let inx = [7.0, 0.27, 0.36, 20.7, 0.045, 45.0, 170.0, 1.001, 3.0, 0.45, 8.8]

const kNN = require('mlhelper').algorithm.kNN;
const parser = require('mlhelper').utils.fileParser;
const path = require('path');

let dt = parser.read_csv(path.join(__dirname, './Pasta1.csv'), {
	index_col: 0,
	delimiter: ';',
	header: 0,
	dataType: 'text'
});
let labels = dt.getHeader();
let dataSet = dt.drop('quality').values;

const charts = require('mlhelper').utils.charts;
let knn = new kNN(dataSet, labels);
let inx = [7.0, 0.27, 0.36, 20.7, 0.045, 45.0, 170.0, 1.001, 3.0, 0.45, 8.8],
	normalInx = knn.autoNormalVector(inx);

console.log(knn.classify(inx, 100)); // 6
charts.drawkNN(kNN.autoNormal(dataSet), labels, normalInx, {
	width: "500px",
	height: "400px",
	size: 15
});

waltergms avatar Nov 03 '17 15:11 waltergms

For drawKnn(), the first parameter is the matrix of train instances, the second parameter is the classes of train instances and the third parameter is a vector of your test instance’s features. The chart util for kNN will draw points for both train instances and the test instance and the different colors of those points represents different classes.

You know, the test instance's class is not known, so it will draw a special point for the test instance's features vector here is normalInx(normalized inx). As color of the point represents different classes, the color of the test instance is default to be white. You can see it in README example. @waltergms

laoqiren avatar Nov 03 '17 15:11 laoqiren