MCPcopy Create free account
hub / github.com/SeldonIO/seldon-server / do_predict

Function do_predict

python/seldon/microservice/predict.py:21–51  ·  view source on GitHub ↗

prediction endpoint - get recommeder from Flask app config - create dataframe from JSON in call - call prediction pipeline - get class id mapping - construct result

()

Source from the content-addressed store, hash-verified

19
20@predict_blueprint.route('/predict',methods=['GET','POST'])
21def do_predict():
22 """
23 prediction endpoint
24
25 - get recommeder from Flask app config
26 - create dataframe from JSON in call
27 - call prediction pipeline
28 - get class id mapping
29 - construct result
30 """
31 input = extract_input()
32 print input
33 pw = current_app.config["seldon_pipeline_wrapper"]
34 pipeline = current_app.config["seldon_pipeline"]
35 df = pw.create_dataframe(input["json"]["data"])
36 preds = pipeline.predict_proba(df)
37 idMap = pipeline._final_estimator.get_class_id_map()
38 formatted_recs_list=[]
39 for index, proba in enumerate(preds[0]):
40 if index in idMap:
41 indexName = idMap[index]
42 else:
43 indexName = str(index)
44 formatted_recs_list.append({
45 "prediction": str(proba),
46 "predictedClass": indexName,
47 "confidence" : str(proba)
48 })
49 ret = { "predictions": formatted_recs_list , "meta": {"modelName" : current_app.config['seldon_model_name']}}
50 json = jsonify(ret)
51 return json

Callers

nothing calls this directly

Calls 5

create_dataframeMethod · 0.80
extract_inputFunction · 0.70
strFunction · 0.50
predict_probaMethod · 0.45
get_class_id_mapMethod · 0.45

Tested by

no test coverage detected