Skip to content

Commit

Permalink
normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzoconti committed Feb 23, 2021
1 parent 230749f commit 55c1e9b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lorenzo/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,39 @@ def solver(task):
encoding = pd.DataFrame(mlb.fit_transform(table), columns=mlb.classes_, index=table.index)


def normalize(df, pizzas):

copy = df.copy()

ingredients = [ingredient for pizza in pizzas for ingredient in pizza.ingredients]

unqique_ingredients = list(set(ingredients))

counts = {}

for ingredient in unqique_ingredients:

count = ingredients.count(ingredient)

counts.update({
ingredient: count
})

copy[ingredient] = copy[ingredient] / count

return copy, counts


def best_pizza(query, pizzas):

query = np.array(encoding.iloc[query.pizza_id].to_list())
pizzas.sort(key=lambda pizza: np.linalg.norm(query - np.array(encoding.iloc[pizza.pizza_id].to_list())),
reverse=True)
return pizzas[0]


normalized_encoding = normalize(encoding, pizzas)

pizza = pizzas.pop(1)
best = best_pizza(pizza, pizzas)

Expand Down

0 comments on commit 55c1e9b

Please sign in to comment.