Skip to content

Instantly share code, notes, and snippets.

View abhisheksoni27's full-sized avatar

Abhishek Soni abhisheksoni27

View GitHub Profile
/**
* https://stackoverflow.com/a/12646864
* Randomize array element order in-place.
* Using Durstenfeld shuffle algorithm.
*/
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
function dressData() {
/**
* There are three different types of Iris flowers
* that this dataset classifies.
*
* 1. Iris Setosa (Iris-setosa)
* 2. Iris Versicolor (Iris-versicolor)
* 3. Iris Virginica (Iris-virginica)
*
function error(predicted, expected) {
let misclassifications = 0;
for (var index = 0; index < predicted.length; index++) {
if (predicted[index] !== expected[index]) {
misclassifications++;
}
}
return misclassifications;
}
function test() {
const result = knn.predict(testSetX);
const testSetLength = testSetX.length;
const predictionError = error(result, testSetY);
console.log(`Test Set Size = ${testSetLength} and number of Misclassifications = ${predictionError}`);
predict();
}
@abhisheksoni27
abhisheksoni27 / matMult.js
Last active June 24, 2017 16:53
Matrix Multiplication using gpu.js
require('brain.js');
require('gpu.js');
//setup environment, ignore
var canvas = document.createElement('canvas');
function specialLogger() {
out.innerHTML = arguments[0];
}
var A = [
[
1, 1
],
[
1, 1
],
[1, 1]
];
#extension GL_EXT_draw_buffers : require
precision highp float;
precision highp int;
precision highp sampler2D;
const float LOOP_MAX = 100.0;
#define EPSILON 0.0000001;
uniform highp vec3 uOutputDim;
uniform highp vec2 uTexSize;
#extension GL_EXT_draw_buffers : require
precision highp float;
precision highp int;
precision highp sampler2D;
const float LOOP_MAX = 100.0;
#define EPSILON 0.0000001;
uniform highp vec3 uOutputDim;
uniform highp vec2 uTexSize;
const KNN = require('ml-knn');
const csv = require('csvtojson');
const prompt = require('prompt');
let knn;
const csvFilePath = 'iris.csv'; // Data
const names = ['sepalLength', 'sepalWidth', 'petalLength', 'petalWidth', 'type']; // For header
let seperationSize; // To seperate training and test data
function train() {
knn = new KNN(trainingSetX, trainingSetY, {k: 7});
test();
}