How to Build Machine Learning Models with JavaScript

Abstract:  Currently, the main languages ​​for modeling in the field of machine learning are Python and R. The machine learning framework Angel launched by Tencent not long ago supports Java and Scala. The author of this article, Abhishek Soni, tells us with actions that JavaScript can also be used to develop machine learning models.

Currently, the main languages ​​for modeling in the field of machine learning are Python and R, and the machine learning framework Angel launched by Tencent not long ago supports Java and Scala. The author of this article, Abhishek Soni, tells us with actions that JavaScript can also be used to develop machine learning models.

JavaScript? Shouldn't I be using Python? Even Scikit-learn doesn't work on JavaScript.

It's possible, in fact, I'm amazed at how ignorant the developers are about it. As far as Scikit-learn is concerned, the developers of Javascript have actually released a suitable library, which will be mentioned in this article. So, let's see what Javascript can do for machine learning.

According to artificial intelligence pioneer Arthur Samuel, machine learning gives computers the ability to learn without being explicitly programmed. In other words, it enables the computer to learn by itself and execute the correct instructions without the need for full human guidance.

Google has been switching its mobile-first strategy to AI-first for a long time.

Why is JavaScript not mentioned in the machine learning world?

 

· Slow (true or false?)

Matrix operations are difficult (there are libraries, like math.js)

· For web development only (there's also Node.js here)

Machine learning libraries are usually in Python (fortunately, there are a lot of JS developers too)

 

Here are some of the pre-made libraries available in JavaScript that contain some machine learning algorithms like Linear Regression, SVM, Naive Bayes, and more.

 

brain.js (neural network)

Synaptic (Neural Network)

Natural (Natural Language Processing)

ConvNetJS (Convolutional Neural Network)

mljs (a set of sub-libraries with various functions)

First, we'll use the mljs regression library to do some linear regression operations.

Reference code: https://github.com/abhisheksoni27/machine-learning-with-js

1. Install the library

 

$ npm install ml-regression csvtojson

 

$ yarn add ml-regression csvtojson

 

ml-regression, as the name suggests, is responsible for linear regression for machine learning.

csvtojson is a fast CSV parser for node.js that allows loading CSV data files and converting them to JSON.

2. Initialize and load data

Download the data file (.csv) and add it to your project.

Link:

http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv

If you have initialized an empty npm project, open index.js and enter the following code.

I put the file in the root directory of the project, if you want to put it elsewhere, please remember to update the csvFilePath.

Original link

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326573212&siteId=291194637