MCPcopy Index your code
hub / github.com/Giyn/DataMiningVisualizationSystem / predict

Function predict

App/main.py:231–257  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

229
230@app.route('/api-predict', methods=['POST', 'GET'])
231def predict() :
232
233 if request.method == 'POST':
234
235 data = json.loads(str(request.data, 'utf-8'))
236
237 dataSet, discrete, textColumn = pullDataSet(str(data['hashKeyI']))
238
239 model, ssler = pullModel(str(data['hashKeyII']))
240
241 if (dataSet is None): return '{"msg" : "数据已过期"}'
242
243 if (model is None): return '{"msg" : "模型已过期"}'
244
245 if(not isinstance(model, NaiveBayesClassifier)) :
246
247 dataSet = DataFrame2NPArray(dataSet)
248
249 res = model.predict(ssler.transform(dataSet))
250
251 else :
252
253 res = model.predict(ssler.transform(dataSet, textColumn))
254
255 return str(DataFrame2Array(DataFrame({'label' : res})))
256
257 return '<h1>请使用POST方法访问</h1>'
258
259@app.before_request
260def before_request():

Callers

nothing calls this directly

Calls 6

pullDataSetFunction · 0.85
pullModelFunction · 0.85
DataFrame2NPArrayFunction · 0.85
DataFrame2ArrayFunction · 0.85
transformMethod · 0.80
predictMethod · 0.45

Tested by

no test coverage detected