SKLearn Model in React-Native App

1.8k Views Asked by At

I'm trying to figure out the best way to use an sklearn model (ex: RandomForestClassifier, etc.) in a react-native app. I've been able to export the model using pickle, but I don't know the best way to utilize it in react-native.

Here are the options I have thought of/researched:

  1. Running actual python code in the react-native app. This could be accomplished using Transcrypt (http://www.transcrypt.org/) which appears to allow you to run python code in a javascript environment.
  2. Converting (or rewriting) the model to use TensorFlow. That way, you could utilize react-native-tensorflow (https://github.com/reneweb/react-native-tensorflow) to use the model in the app.
  3. Creating a python backend service and connecting it to the app by creating a REST api. Therefore the backend handles all of the processing and the prediction the model produces is relayed to the app.

Ideally, I would like the app to be able to run offline, so option 3 would not be preferable. However if option 3 is clearly the simplest/easiest/only solution then I can go with that one.

What would be the recommended way of accomplishing this? Is it one of the options I have researched above, or another option?

1

There are 1 best solutions below

0
On

I expect sklearn to make use of C / C++ code to gain performance. That rules out option 1, not principally, but practically, since load times of PyPyJs (C++ in the browser) are still unpractical.

To run off-line, that leaves option 2 (which by the way can be done with Transcrypt, if you prefer Python over JavaScript).

If scalability isn't a problem, option 3 is a possibility (and I think the simplest). But indeed, being able to run off-line is a considerable advantage.

My advice is to further investigate option 2. If you gain the ability to run such models off-line in a browser, it will pay off on many other occasions. If TensorFlow would utilize the GPU, there would be a massive performance gain.