1

I have one regression model that I did in python with Sklearn, I have trained it and tested prediction. Now I would do predictions from an Android app, so I tested some things like Sklearn-Porter or save in a pkl file but not work. Please help me. How can I do prediction from an android app?

My python code that I would translate:

X = array(listX)
vector = listY
predict=[[99.0, 94.0, 90.0, 83.0, 70.0, 30.0, 50.0, 48.0, 41.0, 52.0, 0, 24.0, 41.0, 44.0, 33.0, 19.0, 0, 17.0, 0, 0, 35.0, 0, 0, 17.0, 0, 0, 0, 0, 17.0, 0, 15.0, 0, 15.0, 0, 15.0, 13.0, 0, 0, 0, 0, 0, 0, 0, 17.0, 0, 0, 15.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61.0]]

poly = PolynomialFeatures(degree=2)
X_ = poly.fit_transform(X)
predict_ = poly.fit_transform(predict)
X_ = np.delete(X_,(1),axis=1) predict_ = np.delete(predict_,(1),axis=1)

clf = LinearRegression()
clf.fit(X_, vector)

print "X=",clf.predict(predict_)[0][0]," Y=",clf.predict(predict_)[0][1]
dd619
  • 5,910
  • 8
  • 35
  • 60

1 Answers1

2

You can export your data from python to java (i guess your app is written in java?) via pmml standard.

export from python : Export python scikit learn models into pmml

import in java: How to use the PMML model in Java?

But due to different programming languages/frameworks etc... one can not guarantee same results of a ml model.

So i suggest you to use some java based ml framework like https://www.cs.waikato.ac.nz/ml/weka/ to create your regression if your android app is written in java.

Florian H
  • 3,052
  • 2
  • 14
  • 25