Browser-ready machine learning algorithms as ES6 modules.
These modules are created to be used in a browser with the ES6 syntax. If you want to just use the modules in a node environment you have to do the following steps:
- convert
importtorequirenotation- convert
exporttomodule.exportsnotation
A live demo is available here.
Documentation can be found here.
ECMAScript standard for importing and exporting features between javascript files.
Example:
//index.js import {MyFunction} from './module1.js'; //named import import {add, sub} from './module2.js'; //multiple named import import defaultF from './module1.js'; //default import let f = new MyFunction(); export const newFunction = function(){ console.info("I'm a brand new function ready to be exported"); } export default DefaultFunction(){ console.info("I'm default"); }Script loading into html file could be done in different ways depending on your needs:
async deferattributes inside script tag : no need to wrap code with jquery document-ready statementtype="module"if you want to load the script server-side (for es6 modules loading)
- Support Vector Machine with different kernels:
- linear
- polynomial
- radial-basis-function (gaussian)
- KNN
- Radial-basis function
- Random Forests
- Logistic Regression
- Neural Net
- multiple layers with costum definition
All algorithms are es6 module. The files needed for the algorithm to work are located in his directory, except for the utility functions.
All algorithms share the basic structure.
Example
export const algorithm = function() {}; // expose this function algorithm.prototype = { // define the function train: function(data, labels) { //set up the environment //train //stored results }, predict: function(point) { //returns the value predicted }, predictClass: function(point) { //returns the class predicted }, getOptions: function() { //returns an object to be used by the "ui" class }, setOptions: function(options) { //set the options } }; // helper functions if neededA bundler for javascript code: you can use nodejs modules in the brower. All js files will be merged and transpiled into one bundle (index.bundle.js), generated into the ./dist folder.
To build the source code run in the command line, inside the package.json directory:
npm install Now you have installed webpack and the project dependecies. Now you can build with:
npm run build To be able to watch the files and automatically build on changes, just run the command:
npm run watch Hey dude! Help me out for a couple of 🍻!