Esempio n. 1
0
def predict():
    json_input = request.json

    current_datatime = strftime('[%Y-%b-%d %H:%M:%S]')
    ip_address = request.headers.get("X-Forwarded-For", request.remote_addr)
    logger.info(
        f'{current_datatime} request from {ip_address}: {request.json}')
    start_prediction = time()

    ID = json_input['ID']
    hf = process_input(json_input)

    prediction_Poisson = model_glm_poisson.predict(hf)
    value_Poisson = prediction_Poisson.as_data_frame()['predict'][0]

    prediction_Gamma = model_glm_gamma.predict(hf)
    value_Gamma = prediction_Gamma.as_data_frame()['predict'][0]

    value_BurningCost = value_Poisson * value_Gamma

    result = {
        'ID': ID,
        'value_Poisson': value_Poisson,
        'value_Gamma': value_Gamma,
        'value_BurningCost': value_BurningCost
    }

    end_prediction = time()
    duration = round(end_prediction - start_prediction, 6)
    current_datatime = strftime('[%Y-%b-%d %H:%M:%S]')
    logger.info(
        f'{current_datatime} predicted for {duration} msec: {result}\n')

    return jsonify(result)
Esempio n. 2
0
def predict():
    json_input = request.get_json(force=True)

    # Request logging
    current_datatime = strftime('[%Y-%b-%d %H:%M:%S]')
    ip_address = request.headers.get("X-Forwarded-For", request.remote_addr)
    logger.info(
        f'{current_datatime} request from {ip_address}: {request.json}')
    start_prediction = time()

    id = json_input['ID']
    user_data = process_input(json_input)

    print(user_data)

    prediction_ClaimInd = xgb_ClaimInd_model.predict(user_data)

    ClaimInd = int(prediction_ClaimInd[0])
    print('prediction:', ClaimInd)

    result = {'ID': id, 'ClaimInd': ClaimInd}

    # Response logging
    end_prediction = time()
    duration = round(end_prediction - start_prediction, 6)
    current_datatime = strftime('[%Y-%b-%d %H:%M:%S]')
    logger.info(
        f'{current_datatime} predicted for {duration} msec: {result}\n')

    return jsonify(result)
Esempio n. 3
0
def predict():
    json_input = request.json

    # Request logging
    current_datatime = strftime('[%Y-%b-%d %H:%M:%S]')
    ip_address = request.headers.get("X-Forwarded-For", request.remote_addr)
    logger.info(
        f'{current_datatime} request from {ip_address}: {request.json}')
    start_prediction = time()

    id = json_input['ID']

    dmatrix = process_input(json_input)

    value_xgb = xgb_model.predict(dmatrix)[0]

    result = {'ID': id, 'ClaimsCount': int(value_xgb)}

    # Response logging
    end_prediction = time()
    duration = round(end_prediction - start_prediction, 6)
    current_datatime = strftime('[%Y-%b-%d %H:%M:%S]')
    logger.info(
        f'{current_datatime} predicted for {duration} msec: {result}\n')

    return jsonify(result)
Esempio n. 4
0
def predict():
    json_input = request.json

    # Request logging
    current_datetime = strftime('[%Y-%b-%d %H:%M:%S]')
    ip_address = request.headers.get("X-Forwarded-For", request.remote_addr)
    logger.info(f'{current_datetime} request from {ip_address}: {request.json}')
    start_prediction = time()

    # id запроса
    id = json_input['ID']

    # подготовка входных данных
    hf = process_input(json_input)

    # предсказание модели
    prediction = model.predict(hf).as_data_frame()
    # вероятности классов
    prob_0 = prediction['p0'][0]
    prob_1 = prediction['p1'][0]
    THRESHOLD = 0.58  # порог вероятности для класса 1
    claim_ind = 1 if prob_1 > THRESHOLD else 0
    claim_ind_front = 'Страховой случай НАСТУПИТ' if bool(claim_ind) else 'Страховой случай НЕ наступит'

    result = {
        'ID': id,
        'prob_0': prob_0,
        'prob_1': prob_1,
        'threshold_prob': THRESHOLD,
        'claim_ind': claim_ind,
        'claim_ind_front': claim_ind_front
    }

    # Response logging
    end_prediction = time()
    duration = round(end_prediction - start_prediction, 6)
    current_datetime = strftime('[%Y-%b-%d %H:%M:%S]')
    logger.info(f'{current_datetime} predicted for {duration} msec: {result}\n')

    return jsonify(result)
Esempio n. 5
0
def predict():
    json_input = request.json

    id = json_input['ID']
    hf = process_input(json_input)

    prediction_Poisson = model_glm_poisson.predict(hf)
    value_Poisson = prediction_Poisson.as_data_frame()['predict'][0]

    prediction_Gamma = model_glm_gamma.predict(hf)
    value_Gamma = prediction_Gamma.as_data_frame()['predict'][0]

    value_BurningCost = value_Poisson * value_Gamma

    result = {
        'ID': id,
        'value_Poisson': value_Poisson,
        'value_Gamma': value_Gamma,
        'value_BurningCost': value_BurningCost
    }

    return jsonify(result)
Esempio n. 6
0
def predict():
    json_input = request.json

    # Request logging
    current_datetime = strftime('[%Y-%b-%d %H:%M:%S]')
    ip_address = request.headers.get("X-Forwarded-For", request.remote_addr)
    logger.info(
        f'{current_datetime} request from {ip_address}: {request.json}')
    start_prediction = time()

    _id = json_input['ID']
    df = process_input(json_input)

    prediction_freq = xgb_freq.predict(xgb.DMatrix(df.values)) - 1
    value_freq = prediction_freq[0]

    prediction_avgclaim = xgb_avgclaim.predict(xgb.DMatrix(df.values))
    value_avgclaim = prediction_avgclaim[0]

    value_burningcost = value_freq * value_avgclaim

    result = {
        'ID': str(_id),
        'value_freq': str(round(value_freq, 2)),
        'value_avgclaim': str(round(value_avgclaim, 2)),
        'value_burningcost': str(round(value_burningcost, 2))
    }

    # Response logging
    end_prediction = time()
    duration = round(end_prediction - start_prediction, 6)
    current_datetime = strftime('[%Y-%b-%d %H:%M:%S]')
    logger.info(
        f'{current_datetime} predicted for {duration} msec: {result}\n')

    return jsonify(result)