Ejemplo n.º 1
0
def get_data():
    print(request)
    area = request.args.get("area")

    property_type = request.args.get("property")
    rental_price = request.args.get("price")
    surface_area = request.args.get("surface")
    plot = request.args.get("plot")

    query_input = []
    for idx, var in enumerate([surface_area, rental_price, property_type]):
        vars_query_input = [0] * len(data.all_var_types[idx])
        idx_query_var = data.all_var_types[idx].index(var)
        vars_query_input[idx_query_var] = 100
        query_input.extend(vars_query_input)

    #reshape query_input to correct format for input to our model
    query_input = np.array(query_input).reshape(1, -1)

    #retrain model based on new data
    trained_model = models.train_model(data.model_data, data.area_names,
                                       data.model_vars)

    #have our trained model make a prediction based on our query input
    _, probabilities = models.pred_proba(model=trained_model,
                                         input_vars=query_input)
    proba_idx = np.where(probabilities[0] == np.amax(probabilities[0]))
    proba_idx = proba_idx[0][0]

    #determine the index of the predicted area within the returned probabiblities array
    pred_area = data.area_names[proba_idx]
    proba = probabilities[0][proba_idx]
    proba = '%.3f' % Decimal(proba)

    #determine how the prediction probability of our previously predicted area has changed
    #due to the change in data variables of this area
    if area is not None:
        proba_idx = data.area_names.index(area)
        new_proba_prev_area = probabilities[0][proba_idx]
        new_proba_prev_area = '%.3f' % Decimal(new_proba_prev_area)
        plot_area = area
    else:
        new_proba_prev_area = None
        plot_area = pred_area

    del probabilities

    if plot is not None:
        plot_data = data.model_data.loc[data.model_data['area_name'] ==
                                        plot_area]
        plot_data = plot_data.loc[:, data.model_vars]
        plot = plots.create_hbar(plot_area, plot_data)
        return jsonify(prediction=pred_area,
                       prediction_proba=proba,
                       area_changed_proba=new_proba_prev_area,
                       plotData=plot)
    else:
        return jsonify(prediction=pred_area,
                       prediction_proba=proba,
                       area_changed_proba=new_proba_prev_area)
Ejemplo n.º 2
0
# Recommender demo by drinkredwine 2018

import app.models as m
import numpy as np

if __name__ == '__main__':
    item_user_data = m.load_data('data/vi_dataset_events.csv')
    model = m.train_model(item_user_data)

with open('data/vi_challenge_uID.csv', 'r') as f:
    data = f.readlines()

for line in data:
    userid = np.float(line)

    recs = m.recommend(userid, d)
    print(userid, recs)



Ejemplo n.º 3
0
 def test_train(self):
     data = load_data('data/user_items.csv')
     train_model(data)