backend.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:berlin-devfest-2016-backend 作者: giansegato 项目源码 文件源码
def predict(path):
    global n
    global model

    parentNode = os.path.split(path)[0]
    j = requests.get(FIREBASE_URL + parentNode + FIREBASE_ENDING_URL).json()
    sample = np.asarray([j[x] for x in j.keys() if "x_" in x]).reshape(1, -1)

    if sample.shape[1] == n:
        j['y_predicted'] = model.predict_proba(sample)[0][1]
        j['action'] = model.predict(sample)[0]
        r = requests.put(FIREBASE_URL + parentNode + FIREBASE_ENDING_URL, data = json.dumps(j))

        print "Features: ", sample
        print "Prediction: ", model.predict_proba(sample) 
    else:
        print "Couldn't make prediction, wrong dimension: ", sample.shape[1], " vs ", n

# 2nd: SSEClient that prints stuff
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号