Ejemplo n.º 1
0
def prepare_data():

    db = Database()
    data_pre = db.findAllRatings()

    user_id = []
    item_id = []
    rating = []

    for row in data_pre:
        user_id.append(row['user_id'])
        item_id.append(row['place_id'])
        rating.append(row['rate'])

    ratings_dict = {'itemID': item_id, 'userID': user_id, 'rating': rating}

    df = pd.DataFrame(ratings_dict)

    reader = Reader(rating_scale=(1, 5))
    data = Dataset.load_from_df(df[['userID', 'itemID', 'rating']], reader)

    items_length = len(df['itemID'].unique())

    return (data, items_length)
 def get(self):
     db = Database()
     result = db.findAllRatings()
     return result