how to change python script into a server

百般思念 提交于 2020-03-26 01:26:20

问题


I am currently working on a project where this project requires a server to be connected to the Android project.

I am confused how to make the python script (inference engine script) that gonna be a server

here the following script that i made :

import numpy as np
import pandas as pd
#from sklearn.ensemble import RandomForestClassifier
#from sklearn.neighbors import KNeighborsClassifier
from sklearn import tree

data = pd.read_csv('datawadek.csv')
y = data.KELAS
x = data.drop('KELAS', axis = 1)

#rf = RandomForestClassifier(n_estimators=20)
#nn =  KNeighborsClassifier()
cart = tree.DecisionTreeClassifier()

#rf.fit(x,y)
cart = cart.fit(x,y)

print (cart.predict([[1,1,2,3,3,1,1,2]]))

im still working on it and got stuck so if so if there are any suggestions or solutions please let me know.

by the way my project is to create an expert system application with data mining methods.


回答1:


Try solution if you want a web service for the same, please refer to excellent guide from Miguel simple web service

#!flask/bin/python
from flask import Flask

app = Flask(__name__)

@app.route('/', methods=['GET','POST'])
def index(input):
    # input = [[1,1,2,3,3,1,1,2]]
    # do all processing here

    return cart.predict(input)

if __name__ == '__main__':
    app.run(debug=True)


来源:https://stackoverflow.com/questions/58911068/how-to-change-python-script-into-a-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!