A Practical Guide to Brain.js

75
0

What is Brain.js?

Machine learning and neural network is the most exciting frontier for software development. As per Stack Overflow, survey javascript is the most widely usable programing language and is not limited only to developing web applications right now we can develop desktop, and mobile applications, and the most advance and secure systems. Advance systems mean to be predicting results by training or building data modules which we normally do with python but now javascript is capable to build and train data modules as well.

There are a number of machine learning javascript libraries available such as TensorFlow, ml5, WebGL, and brain.js but the most essential and used to build advanced systems is the brain.js which we are going to explore in this guide.

Why Brain.js?

After a basic introduction to brain.js, many developers may have questioned whether is javascript good for machine learning and why we need to know about brain.js the simple answer is yes javascript is a good fit for machine learning, and many developers use and explore javascript space. There are many applications of brain.js already available where we can work on modules and develop an advanced system that predicts future results.

Brain js is the fastest processing library because of GPU computations and even If you don’t have GPU. Beginners can directly jump into brain js because you don’t need neural network knowledge to start with it just basic javascript fundamentals are enough to start with brian js.

How to get started with Brain.js

To get started with brain js you need a basic understanding of javascript and an introduction to the neural networks. The brain.js is considered the second most widely used javascript library after TensorFlow. It’s open source javascript library you can join the community and start contributing to it, the following ways help you to get started with brain.js.

– Official Documentations

– Tutorials

– Community resources

– Contributing to it

– Articles and Manual resources

There are multiple resources available to learn about brain.js join their social community and will share the best resources with you, find articles and instruction manuals developed by other developers, and always start with official documentation. Building projects are the best way to learn any library or framework start building small and individual projects which help you to understand it properly.

Applications and Examples of Brain.js

Brain.js help you to create machine learning modules and neural network applications, you can build advanced security applications using brain.js.

Emotion detection application

Future Results predicting application

Cloudinary image recognition add-on system

Neural network application

Input-output Guessing system

These are some basic applications of brain.js but you can explore & learn more about them and now we are building a small application using brian.js.

Prerequisites

– Node.js

– NPM installed on your system

– Basic understanding of Javascript

Installed Brain. js or use CDN

Javascript Basics

npm install brain.js

CDN <script src=”//unpkg.com/brain.js”></script>

Create index.html and app.js

index.html

HTML

<html>
  <head>
    <script src="//unpkg.com/brain.js"></script>
    <script src = " index.js"> </script>
  </head>
</html>

app.js


Javascript

const net = new.brain.NeuralNetwork({hiddenLayers :[3]});
Const _Data = [
    {input : [0,0], output: [0]},
    {input : [0,1], output: [1]}
  ];
net.train(_Data);
console.log(net.run([0,0]));
console.log(net.run([0,1]));

The above code will predict the possibilities from 0 and 1 which is more executable, you can take it as 0 means nothing and 1 means single point value. This is a small application you can develop a cricket match-winning prediction system with this idea here we take two inputs you can take more as per requirements. The input [0,0] shows low possibilities than input [0,1] values. You can train data using brain.js and develop several applications using it. There are multiple methods available to train and develop an application.

Wrap-up

In this article, we discussed a couple of concepts about neural networks and machine learning that are used in javascript using brain.js and how it uses these concepts sequentially. The brain is the fastest javascript library to build a neural network you can explore and build more stuff with it.

==========================================

➡️ Connect with me

[Twitter] https://twitter.com/ganeshstwt

[Linkedin] https://www.linkedin.com/in/ganeshpatil386386/

[Github] https://github.com/ganeshpatil386386