This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function error(predicted, expected) { | |
let misclassifications = 0; | |
for (var index = 0; index < predicted.length; index++) { | |
if (predicted[index] !== expected[index]) { | |
misclassifications++; | |
} | |
} | |
return misclassifications; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('brain.js'); | |
require('gpu.js'); | |
//setup environment, ignore | |
var canvas = document.createElement('canvas'); | |
function specialLogger() { | |
out.innerHTML = arguments[0]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var A = [ | |
[ | |
1, 1 | |
], | |
[ | |
1, 1 | |
], | |
[1, 1] | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function train() { | |
knn = new KNN(trainingSetX, trainingSetY, {k: 7}); | |
test(); | |
} |