-
Notifications
You must be signed in to change notification settings - Fork 0
/
airbnb_ratings_api.py
52 lines (38 loc) · 1.08 KB
/
airbnb_ratings_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import json
import pickle
import numpy as np
import pandas as pd
from xgboost import XGBClassifier
model = pickle.load(open("model/model.pickle", "rb"))
columns = pickle.load(open("model/model_columns.pickle", "rb"))
def recommendation():
pass
def predict_ratings(data):
data2 = {}
for k, v in data.items():
data2[k] = [v]
query = pd.get_dummies(pd.DataFrame.from_dict(data2))
for col in columns:
if col not in query.columns:
query[col] = 0
query = query[columns]
prob_5stars = model.predict_proba(query)[0, 1]
print(query.shape)
# Recommendation
score = {}
for col in list(columns[14:42]):
rec = query.copy()
if query[col][0] == 0:
rec[col][0] = 1
prob_new = model.predict_proba(rec)[0, 1]
score[col] = prob_new
highest = max(score, key=score.get)
result = {
'result': str(prob_5stars),
'add': highest,
'improvement': str(score.get(highest))
}
return result
if __name__ == '__main__':
pass # print(predict_ratings(example))