Sklearn Model (Python) with NodeJS (Express): how to connect both?
Asked Answered
G

1

12

I have a web server using NodeJS - Express and I have a Scikit-Learn (machine learning) model pickled (dumped) in the same machine.

What I need is to demonstrate the model by sending/receiving data from it to the server. I want to load the model on startup of the web server and keep "listening" for data inputs. When receive data, executes a prediction and send it back.

I am relatively new to Python. From what I've seen I could use a "Child Process" to execute that. I also saw some modules that run Python script from Node.

The problem is I want to load the model once and let it be for as long as the server is on. I don't want to keep loading the model every time due to it's size. How is the best way to perform that?

The idea is running everything in a AWS machine.

Thank you in advance.

Gastronome answered 5/3, 2017 at 16:2 Comment(0)
P
8

My recommendation: write a simple python web service (personally recommend flask) and deploy your ML model. Then you can easily send requests to your python web service from your node back-end. You wouldn't have a problem with the initial model loading. it is done once in the app startup, and then you're good to go

DO NOT GO FOR SCRIPT EXECUTIONS AND CHILD PROCESSES!!! I just wrote it in bold-italic all caps so to be sure you wouldn't do that. Believe me... it potentially go very very south, with all that zombie processes upon job termination and other stuff. let's just simply say it's not the standard way to do that.

You need to think about multi-request handling. I think flask now has it by default

I am just giving you general hints because your problem has been generally introduced.

Pressing answered 28/5, 2020 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.