Traditionally, Machine Learning applications are using R or Python.

But JavaScript has a great future as an Machine Learning language:

  • JavaScript is well known. All developers can use it.
  • Security is built in. JavaScript cannot access your files.
  • JavaScript is faster than Python.
  • JavaScript can use hardware acceleration.
  • JavaScript runs in the browser

JavaScript is Good for Machine Learning

Machine Learning can be math-heavy. The nature of neural networks is highly technical, and the jargon that goes along with it tends to scare people away.

This is where JavaScript comes to help, with easy to understand software to simplifying the process of creating and training neural networks.

With new Machine Learning libraries, JavaScript developers can add Machine Learning and Artificial Intelligence to web applications.


WebGL API

WebGL is a JavaScript API for rendering 2d and 3D graphics in any browser.

WebGL can run on both integrated and standalone graphic cards in any PC.

WebGL brings 3D graphics to the web browser. Major browser vendors Apple (Safari), Google (Chrome), Microsoft (Edge), and Mozilla (Firefox) are members of the WebGL Working Group.

 


JavaScript Machine Learning Libraries

Machine Learning in the Browser means:

  • Machine Learning in JavaScript
  • Machine Learning for the Web
  • Machine Learning for Everyone
  • Machine Learning on more Platforms

Advantages:

  • Easy to use. Nothing to install.
  • Powerful graphics. Browsers support WebGL.
  • Better privacy. Data can stay on the client.
  • More platforms. JavaScript runs on mobile devices.

Math.js

Math.js is an extensive math library for JavaScript and Node.js.

Math.js is powerful and easy to use. It comes with a large set of built-in functions, a flexible expression parser, and solutions to work with many data types like numbers, big numbers, complex numbers, fractions, units, arrays, and matrices.


Brain.js

Brain.js is a JavaScript library that makes it easy to understand Neural Networks because it hides the complexity of the mathematics.

Brain.js is simple to use. You do not need to know neural networks in details to work with Brain.js.

Brain.js provides multiple neural network implementations as different neural nets can be trained to do different things well.

 


ml5.js

ml5.js is trying to make machine learning more accessible to a wider audience.

The ml5 team is working to wrap machine learning functionality in friendlier ways.

The example below uses only three lines of code to classify an image:

<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"></script>
<script src="https://unpkg.com/ml5@latest/dist/ml5.min.js"></script>
<body>
<h1>Image Classification</h1>
<h2>With MobileNet and ml5.js</h2>
<div id="result">Scanning ...</div>
<img id="image" src="pic1.jpg" width="100%">

<script>
// Initialize Image Classifier with MobileNet.
const classifier =  ml5.imageClassifier('MobileNet');
classifier.classify(document.getElementById("image"), gotResult);

// Function to run when results arrive
function gotResult(error, results) {
  const element = document.getElementById("result");
  if (error) {
    element.innerHTML = error;
  } else {
    let num = results[0].confidence * 100;
    element.innerHTML = results[0].label + "<br>Confidence: " + num.toFixed(2) + "%";
  }
}
</script>
</body>
</html>

Image Classification

With MobileNet and ml5.js

robin, American robin, Turdus migratorius
Confidence: 95.52%

 

Try substitute "pic1.jpg" with "pic2.jpg" and "pic3.jpg".


TensorFlow

is a web application written in d3.js.

With TensorFlow Playground you can learn about Neural Networks (NN) without math.

In your own Web Browser you can create a Neural Network and see the result.

TensorFlow.js was previously called Tf.js and Deeplearn.js.


Plotting in the Browser

Here is a list of some JavaScript libraries to use for both Machine Learning graphs and other HTML charts:

 


Plotting Equations

<!DOCTYPE html>
<html>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

<body>
<h1>Using Plotly.js</h1>
<p>Enter Equation:</p>
<p><input id="equation" type="text" value="x * 2 + 17"></p>
<p>
<button onclick='plot("scatter")'>Scatter</button>
<button onclick='plot("lines")'>Draw Line</button>
</p>
<div id="myPlot" style="width:100%;max-width:700px"></div>

<script>
function plot(type) {
const exp = document.getElementById("equation").value;
const xValues = [];
const yValues = [];
let mode = "lines";
if (type == "scatter") {mode = "markers"}

// Generate values
for (let x = 0; x <= 10; x += 1) {
  xValues.push(x);
  yValues.push(eval(exp));
}

// Display using Plotly
const data = [{x:xValues, y:yValues, mode:mode, type:"scatter"}];
const layout = {title: "y = " + exp};
Plotly.newPlot("myPlot", data, layout);
}
</script>

</body>
</html>

 


Plotting Values

<!DOCTYPE html>
<html>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<body>
<h1>Using Plotly.js</h1>

<p>X values:<br>
<input id="xvalues" style="width:95%" type="text"
value="50,60,70,80,90,100,110,120,130,140,150"></p>

<p>Y values:<br>
<input id="yvalues" style="width:95%" type="text"
value="7,8,8,9,9,9,10,11,14,14,15"></p>

<button onclick='plot("scatter")'>Scatter</button>
<button onclick='plot("lines")'>Draw Lines</button>

<div id="myPlot" style="width:100%;max-width:700px"></div>

<script>
function plot(type) {
const xArray = document.getElementById("xvalues").value.split(',');
const yArray = document.getElementById("yvalues").value.split(',');
let mode = "lines";
if (type == "scatter") {mode = "markers"}
  Plotly.newPlot("myPlot", [{x:xArray, y:yArray, mode:mode, type:"scatter"}]);
}
</script>

</body>
</html>

 



Machine Learning Languages

Programming languages involved in Machine Learning and Artificial Intelligence are:

  • LISP
  • R
  • Python
  • C++
  • Java
  • JavaScript
  • SQL

LISP

LISP is the second oldest programming language in the world (1958), one year younger than Fortran (1957).

The term Artificial Intelligence was made up by John McCarthy who invented LISP.

LISP was founded on the theory of Recursive Functions (self modifying functions), and this is very suitable for Machine Learning programs where "self-learning" is an important part of the program.

 


 

The R Language

R is a programming language for Graphics and Statistical computing.

R is supported by the .

R comes with a wide set of statistical and graphical techniques for:

  • Linear Modeling
  • Nonlinear Modeling
  • Statistical Tests
  • Time-series Analysis
  • Classification
  • Clustering

Python

Python is a general-purpose coding language. It can be used for all types of programming and software development.

Python is typically used for server development, like building web apps for web servers.

Python is also typically used in Data Science.

An advantage for using Python is that it comes with some very suitable libraries:

  • NumPy (Library for working with Arrays)
  • SciPy (Library for Statistical Science)
  • Matplotlib (Graph Plotting Library)
  • NLTK (Natural Language Toolkit)
  • TensorFlow (Machine Learning)

 

 

Languages


C++

C++ holds the title: "The worlds fastest programming language".

Because of the speed, C++ is a preferred language when programming Computer Games.

It provides faster execution and has less response time which is applied in search engines and development of computer games.

Google uses C++ in Artificial Intelligence and Machine Learning programs for SEO (Search Engine Optimization).

SHARK is a super-fast C++ library with support for supervised learning algorithms, linear regression, neural networks, and clustering.

MLPACK is also a super-fast machine learning library for C++.


Java

Java is another general-purpose coding language that can be used for all types of software development.

For Machine Learning, Java is mostly used to create algorithms, and neural networks.


SQL

SQL (Structured Query Language) is the most popular language for managing data.

Knowledge of SQL databases, tables and queries helps data scientists when dealing with data.

SQL is very convenient for storing, manipulating, and retrieving data in databases.

 

 
Machine Learning in JavaScript

Login
ADS CODE