Machine Learning, AI and JS: Breaking the boundaries

Machine Learning provides computers with the ability to learn without being explicitly programmed.      – Arthur Samuel

The term machine learning was coined in 1959 by Arthur Samuel, an American pioneer in the field of computer gaming and artificial intelligence.

Machine learning is a sub-field of artificial intelligence (AI), the intelligence of a machine that could successfully perform any intellectual task that a human being can.

It provides systems the ability to learn by themselves and improve gradually from experience without human intervention. The process of learning begins with observations and adjust actions accordingly to make a better decision in the future.

Basically, machine learning can be grouped into following categories:

Supervised machine learning algorithms

The approach is to apply the past learnings to the new data to predict future actions using labeled examples. The purpose is to recognize a pattern in a given dataset. The data set is differentiated as input and output. The algorithm is trained to map input to output on the basis of learning with the given dataset known as training phase. A cost function estimates the performance of the current algorithm during the training phase. It also adjusts the parameters of the algorithm based on the outcomes. After the training, there comes inference phase used to make predictions for input data points giving output data points.

If the output depends on a single-valued input it is called a univariate and if it depends on the multi-valued input it is called a multivariate.

If the information used to train is labeled providing continuous values as an output then it is known as linear regression. On the other hand, if the information used to train is classified and the output is categorical value then it is known as logistic regression.

Unsupervised machine learning algorithms

The approach is used when the training dataset is neither classified nor labeled, only the features without any given output. It explores the data and allows the system to infer a function for describing a hidden structure from unlabelled data. The system doesn’t figure out the right output.

Semi-supervised machine learning algorithms

This algorithm lies somewhere between the supervised and unsupervised learning. The training dataset used in this algorithm is both labeled – a small amount and unlabelled – a large amount. The systems that use this method are able to considerably improve learning accuracy. It is preferred when the skilled and relevant resources are required by the labeled data either to train it or learn from it.

Reinforcement machine learning algorithms

This algorithm does not involve any training dataset rather it learns by interacting with the environment by trial and error search and delayed reward. It learns from experience by repeating a learning process. It allows the system to determine the ideal behavior within a specific context automatically in order to maximize its performance. Learning by reward feedback that which action is best is known as the reinforcement signal.

The world is going to change drastically in the coming 25 years in terms of technology which majorly rely on AI like drones, self-driving cars etc. The recent act of giving citizenship to Sophia, a robot by Saudi Arabia embrace the close relationship between artificial intelligence (AI) and real life. All of these requires the system to be aware of the surrounding environment in order to respond.

Human brain deal with the complexity by the help of neurons but a single neuron is not capable enough to take any action, therefore they are combined together forming neural networks which make us able to recognize the world around us and interact. Similarly, in AI neurons are like transistors with the states – on or off or input values from -1 to +1.

Machine Learning, AI and JS

Javascript has evolved from merely a scripting script in the era of Netscape to a more robust and powerful language now. Today the browser is gradually becoming the platform for compiling and running apps, and javascript is at the center of it. And, now breaking all the boundaries, javascript has opened new avenue in ML and AI.

There are a handful of libraries in JavaScript which give a framework around algorithms and neural networks for Machine Learning. Following are the basic steps to train the model using JavaScript:

1. Install the libraries

2. Initialize the library and load the Data

3. Dressing Data to populate variables and get it ready for execution

4. Train your model and start predicting

TensorFlow.js – A JavaScript library for machine intelligence

It is the most popular hardware-accelerated open source JavaScript library for machine intelligence which was once known as deeplearn.js supported by the Google Brain team and a community of more than 50 contributors. As the name suggests, it is modeled after TensorFlow and is written in typescript.

It enables training of neural networks within a browser without any software installation. It supports WebGL, a JavaScript API that is used for rendering 2D and 3D graphics within any browser. It allows importing an existing pre-trained model which can also be re-trained by using data collected in the browser. This technique is known as ‘Image Retraining’ which allows re-train the model efficiently in less time even if the amount of data is small.

The API essentially has three parts.

1. The functions, array-like structures holding the data, to create, initialize and transform tensors.

2. The operations that are performed on tensors like mathematical operations, normalization, reduction, and convolution.

3. Model training

Apart from these, the remaining part of API is for setting the environment and managing the resources.

It is clear that the opportunities in the field of machine learning have grabbed attention with the availability of a bunch of resources. It is encouraging to know the fact that TensorFlow.js doesn’t exist a year ago. Interested JavaScript developers can be a part of this revolution by using their skills and spending some time to understand the concepts behind.


I am a technology freak with passion for UI technology.

Leave a Reply