We’ve covered machine learning in our previous article on Hot Topics in Web Development, so make sure you’ll check it for more information on other trends currently rocking the dev world. Herein specifically, we’ll concentrate on machine learning, languages involved, and look at the TOP Best Machine Learning libraries that are written in JavaScript.
Let’s briefly define Machine Learning before we move on to the fun part. Machine Learning from now on referred to as ML) is a branch of Artificial Intelligence (AI) that’s based on the idea that systems can learn from data, analyze and establish patterns, and make decisions based on those findings without the need for or with minimal human intervention and interaction. To have a brief overview of the data science, consider reading DS: Bigger Picture on the blog.
Speaking of languages, ML is usually associated with Python and R.; first of all, because these languages are suitable for non-programmers and there are comprehensive ML libraries available, which make them easy to use. In other cases, ML algorithms are implemented in C, C++, Elixir, Java, .Net, Perl, Ruby, SAS, and Scala. However, since during the past couple of years JS popularity skyrocketed, more and more people have started using JS, creating some awesome JS ML libraries, enabling implementation of ML methods both in the browser and on the backend using Node.js.
Natural Language Processing
natural
Natural is a general natural language facility for Node.js. It currently supports:
- Tokenization
- Stemming and sentiment analysis (currently in eight languages)
- Calculation of strings distances and matching similar strings
- Classification (naive Bayes, logistic regression, and maximum entropy)
- Phonetics, tf-idf, WordNet, string similarity, and some inflections
nlp.js
nlp.js is an NLP library built-in node over Natural.
nlp.js is currently able to
- Guess the language from a phrase
- Calculate distance between two strings
- Search the best substring of a string with less Levenshtein distance to a given pattern
- Get stemmers and tokenizers for several languages
Perform a sentiment analysis for phrases (with negation support) - Support named entity recognition and management, multilanguage, and accepting similar strings
- Supports classification: classifies utterances into intents (Natural Language Processing Classifier)
- Generates an answer from intents and conditions (Natural Language Generation Manager)
- Manages several languages (NLP Manager)
- Supports 29 languages (even fantasy languages)
There is a version of NLP.js that works in React Native, so you can build chatbots that can be trained and executed in the mobile environment without the need for the Internet connection.
Data Analysis / Data Visualization
Sigma.js
Sigma is a JavaScript library dedicated to graph drawing.
It makes easy to publish networks on Web pages and allows developers to integrate network exploration in rich Web applications. Suitable for both beginners and advanced users alike.
Features:
- The default configuration deals with mouse and touch support, refreshes and rescales when the container changes and renders on WebGL (provided a browser supports it) and Canvas.
- Easily customizable settings allowing users to add their own functions to render nodes and edges however they like it.
- Public API makes it possible to modify data, move the camera, refresh the rendering, listen to events and add different degrees of interactivity.
D3.js
D3.js is a JavaScript library for manipulating documents based on data. D3 brings data to life using HTML, SVG, and CSS. The library allows you to bind arbitrary data to a Document Object Model (DOM), and then apply data-driven transformations to the document. It’s not a monolithic framework, but instead — seeks to provide every conceivable feature, efficiently manipulating documents based on data, avoiding proprietary representation, allowing for more flexibility, and exposing the full capabilities of web standards such as HTML, SVG, and CSS. D3’s functional style allows code reuse through a diverse collection of official and community-developed modules.
Examples: https://github.com/d3/d3/wiki/Gallery
One representative example: https://bl.ocks.org/mbostock/raw/3231298/
Nivo
Nivo is built on top of the awesome d3 and Reactjs libraries.
Nivo is all about React components built on top of d3 that help build DataViz apps with ease.
Features:
- Customization
- Motion/transitions, powered by react-motion
- Isomorphic rendering
- Component playground
- Good supporting documentation
- SVG charts, HTML charts, Canvas charts
- Server-side rendering API
- Legends
- Annotations
- SVG patterns
- Gradients
- Responsive charts
General-Purpose Machine Learning
Brain.js
Brain.js is are neural networks in JavaScript – continued community fork of Brain.
brain.js is focused on training and applying feedforward and recurrent neural networks. It also provides such advanced options as using GPU to train networks, asynchronous training that can fit multiple networks in parallel, and cross-validation, a more sophisticated validation method. brain.js saves and loads models to/from JSON files.
A fun and practical 19-part course on Brain.js can be found here.
TensorFlow.js
A WebGL-accelerated, browser-based JavaScript library for training and deploying ML models.
TensorFlow.js was previously known as deeplearning.js, a Google’s mastermind project that paved the way for making machine learning easier to access and understand. All TensorFlow.js examples are written using the latest features of the JavaScript language — hence, suitable for an experienced data scientist with advanced JavaScript knowledge, rather than a beginner coder.
Freecodecamp:
WebDNN
Fast Deep Neural Network Javascript Framework. WebDNN uses next-generation JavaScript API, WebGPU for GPU execution, and WebAssembly for CPU execution.
WebDNN is written in TypeScript and Python and offers JavaScript and Python APIs. WebDNN uses a web browser as an installation-free DNN execution framework. This framework optimizes a trained DNN model to compress the model data and accelerate the execution and executes it with novel JavaScript API such as WebAssembly and WebMetal to achieve zero-overhead execution.
Examples: https://mil-tokyo.github.io/webdnn/#neural-style-transfer
ml.js
Ml.js is machine learning and numerical analysis tools for Node.js and the Browser.
Ml.js is a comprehensive general-purpose Machine Learning library written in JS. The library itself is a compilation of the tools developed in the mljs organization. Although it’s primarily written for use in the browser, you may add your own dependencies to use in Node.js as well: those are labeled with ml-, so — pretty easy to find. The library supports the following routines: bit operations on arrays, sorting, hash tables, random number generation; linear algebra, array manipulation, optimization, statistics; cross-validation, supervised and unsupervised learning.
ml.js supports the following unsupervised learning methods: principal component analysis, hierarchical clustering, and K-means clustering.
Among the supervised learning you’ll find the following methods:
- Naive Bayes
- K-Nearest Neighbor (KNN)
- Confusion matrix
- Decision tree classifier
- Random forest classifier, among others
- Supported AI networks are Feedforward Neural Networks and Kohonen networks
Ml5
ml5 is built on top of TensorFlow.js with no other external dependencies, the library is specifically tailored at a beginner coder and uses beginner-friendly JavaScript.
If you want to learn more about this library, then this is a great video to start with:
Misc
simple-statistics – A JavaScript implementation of descriptive, regression, and inference statistics. Implemented in literate JavaScript with no dependencies, designed to work in all modern browsers (including IE) as well as in Node.js. The library helps coders harness the power of statistics and statisticians understand code. The library is exhaustively documented, written in a simple and friendly style, and thoroughly tested.
MLPleaseHelp – MLPleaseHelp is a simple ML resource search engine. You can use this search engine right now at https://jgreenemi.github.io/MLPleaseHelp/, provided via Github Pages.
GitHub resources:
Awesome Machine Learning Libraries
The University of Tokyo Machine Intelligence Laboratory List of Libraries
Machine Learning Frameworks by Industries