Machine Learning REST API

Yogesh Abhyankar
2 min readNov 7, 2019

--

As machine learning is a current hot topic, thought of having a go at it.
There are lot of machine learning libraries available to use. I came across a post wherein machine learning library was used to demonstrate the concept.
To make it more generic, I created a REST API so it can be consumed in another application

This is how it goes —
You can refer to my github code here and download files for reference

This node module used ml-regression library
Here is high level logic -
1. place the data file in csv format in project root folder
2. format — id(record identifier),x,y,series (x and y are main elements that we are interested in), as in any machine learning algorithm, more the available data better the prediction outcome
3. use csvtojson utility to convert the csv data in json format
4. x and y are extracted in a separate arrays
5. regression model works on the x and y arrays, (simple linear regression algorithm is used here)
6. model generates a correlation between x and y
Now if you pass some value to x, it will calculate corresponding value of y
that’s it, we wrap it up in a express router and our API is ready for use.
Run node index.js at command prompt and call url in REST client. Pass the value of x as parameter to API and you will get return value of y. url to call - http://localhost:5000/10 here 10 is value of x

Node prompt
REST client

As this is a REST API, you can call it from any application and use machine learning features. off course this is a relatively simple example using a linear regression algorithm, but building on similar approach you can develop a complex solution as well. Happy machine learning…

--

--

Yogesh Abhyankar

A passionate IT consultant, focused on shifts in technological evolution. Enthusiast to learn Machine Learning, Chatbot and related stuff