问题
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