1
#Let the random-forest model be: *rf_model*

from kale.common.serveutils import serve

kfserver = serve(rf_model) #model is now being deployed

#prepare data for prediction

data = [row.tolist() for _, row in 
train_df[predictor_var].head(10).iterrows()]

data_json = json.dumps({"instances": data})

#prediciton using deployed model:

pred = kfserver.predict(data_json)

问题1:返回的pred是类标签:0/1。如何返回概率?

学习后我尝试了以下方法:kale.common.serveutils.predict

#let HOST be the host name of deployed model

#let the URL of calling the deployed model be: http://xxx:predict

headers = {"content-type": "application/json", "Host": HOST}

pred_2 = requests.post(url = URL, data=data_json, headers=headers)

问题2:但不清楚,在哪里设置参数,所以pred_2会返回概率?

4

0 回答 0