@Test public void testResults() { getAlgo().train(getTrainOrderItems(), getTrainOrders()); testSingleResults(); testMultiResults(); }
@Override public void train(List<OrderItem> orderItems, List<Order> orders) { long tic = System.currentTimeMillis(); totalProducts = new HashSet<>(); Map<Long, OrderItemSet> unOrderizeditemSets = new HashMap<>(); for (OrderItem orderItem : orderItems) { if (!unOrderizeditemSets.containsKey(orderItem.getOrderId())) { unOrderizeditemSets.put(orderItem.getOrderId(), new OrderItemSet()); unOrderizeditemSets.get(orderItem.getOrderId()).setOrderId(orderItem.getOrderId()); } unOrderizeditemSets.get(orderItem.getOrderId()).getOrderset().put(orderItem.getProductId(), orderItem.getQuantity()); if (!totalProducts.contains(orderItem.getProductId())) { totalProducts.add(orderItem.getProductId()); } } Map<Order, OrderItemSet> itemSets = new HashMap<>(); for (Long orderid : unOrderizeditemSets.keySet()) { Order realOrder = findOrder(orders, orderid); itemSets.put(realOrder, unOrderizeditemSets.get(orderid)); } userItemSets = new HashMap<>(); for (Order order : itemSets.keySet()) { if (!userItemSets.containsKey(order.getUserId())) { userItemSets.put(order.getUserId(), new HashSet<OrderItemSet>()); } itemSets.get(order).setUserId(order.getUserId()); userItemSets.get(order.getUserId()).add(itemSets.get(order)); } userBuyingMatrix = createUserBuyingMatrix(userItemSets); executePreprocessing(); LOG.info("Training recommender finished. Training took: " + (System.currentTimeMillis() - tic) + "ms."); trainingFinished = true; }
AbstractRecommender implements IRecommender { @Override public void train(List<OrderItem> orderItems, List<Order> orders) { long tic = System.currentTimeMillis(); totalProducts = new HashSet<>(); Map<Long, OrderItemSet> unOrderizeditemSets = new HashMap<>(); for (OrderItem orderItem : orderItems) { if (!unOrderizeditemSets.containsKey(orderItem.getOrderId())) { unOrderizeditemSets.put(orderItem.getOrderId(), new OrderItemSet()); unOrderizeditemSets.get(orderItem.getOrderId()).setOrderId(orderItem.getOrderId()); } unOrderizeditemSets.get(orderItem.getOrderId()).getOrderset().put(orderItem.getProductId(), orderItem.getQuantity()); if (!totalProducts.contains(orderItem.getProductId())) { totalProducts.add(orderItem.getProductId()); } } Map<Order, OrderItemSet> itemSets = new HashMap<>(); for (Long orderid : unOrderizeditemSets.keySet()) { Order realOrder = findOrder(orders, orderid); itemSets.put(realOrder, unOrderizeditemSets.get(orderid)); } userItemSets = new HashMap<>(); for (Order order : itemSets.keySet()) { if (!userItemSets.containsKey(order.getUserId())) { userItemSets.put(order.getUserId(), new HashSet<OrderItemSet>()); } itemSets.get(order).setUserId(order.getUserId()); userItemSets.get(order.getUserId()).add(itemSets.get(order)); } userBuyingMatrix = createUserBuyingMatrix(userItemSets); executePreprocessing(); LOG.info("Training recommender finished. Training took: " + (System.currentTimeMillis() - tic) + "ms."); trainingFinished = true; } }
AbstractRecommender implements IRecommender { @Override public void train(List<OrderItem> orderItems, List<Order> orders) { long tic = System.currentTimeMillis(); totalProducts = new HashSet<>(); Map<Long, OrderItemSet> unOrderizeditemSets = new HashMap<>(); for (OrderItem orderItem : orderItems) { if (!unOrderizeditemSets.containsKey(orderItem.getOrderId())) { unOrderizeditemSets.put(orderItem.getOrderId(), new OrderItemSet()); unOrderizeditemSets.get(orderItem.getOrderId()).setOrderId(orderItem.getOrderId()); } unOrderizeditemSets.get(orderItem.getOrderId()).getOrderset().put(orderItem.getProductId(), orderItem.getQuantity()); if (!totalProducts.contains(orderItem.getProductId())) { totalProducts.add(orderItem.getProductId()); } } Map<Order, OrderItemSet> itemSets = new HashMap<>(); for (Long orderid : unOrderizeditemSets.keySet()) { Order realOrder = findOrder(orders, orderid); itemSets.put(realOrder, unOrderizeditemSets.get(orderid)); } userItemSets = new HashMap<>(); for (Order order : itemSets.keySet()) { if (!userItemSets.containsKey(order.getUserId())) { userItemSets.put(order.getUserId(), new HashSet<OrderItemSet>()); } itemSets.get(order).setUserId(order.getUserId()); userItemSets.get(order.getUserId()).add(itemSets.get(order)); } userBuyingMatrix = createUserBuyingMatrix(userItemSets); executePreprocessing(); LOG.info("Training recommender finished. Training took: " + (System.currentTimeMillis() - tic) + "ms."); trainingFinished = true; }  }
AbstractRecommender implements IRecommender { @Override public void train(List<OrderItem> orderItems, List<Order> orders) { long tic = System.currentTimeMillis(); totalProducts = new HashSet<>(); Map<Long, OrderItemSet> unOrderizeditemSets = new HashMap<>(); for (OrderItem orderItem : orderItems) { if (!unOrderizeditemSets.containsKey(orderItem.getOrderId())) { unOrderizeditemSets.put(orderItem.getOrderId(), new OrderItemSet()); unOrderizeditemSets.get(orderItem.getOrderId()).setOrderId(orderItem.getOrderId()); } unOrderizeditemSets.get(orderItem.getOrderId()).getOrderset().put(orderItem.getProductId(), orderItem.getQuantity()); if (!totalProducts.contains(orderItem.getProductId())) { totalProducts.add(orderItem.getProductId()); } } Map<Order, OrderItemSet> itemSets = new HashMap<>(); for (Long orderid : unOrderizeditemSets.keySet()) { Order realOrder = findOrder(orders, orderid); itemSets.put(realOrder, unOrderizeditemSets.get(orderid)); } userItemSets = new HashMap<>(); for (Order order : itemSets.keySet()) { if (!userItemSets.containsKey(order.getUserId())) { userItemSets.put(order.getUserId(), new HashSet<OrderItemSet>()); } itemSets.get(order).setUserId(order.getUserId()); userItemSets.get(order.getUserId()).add(itemSets.get(order)); } userBuyingMatrix = createUserBuyingMatrix(userItemSets); executePreprocessing(); LOG.info("Training recommender finished. Training took: " + (System.currentTimeMillis() - tic) + "ms."); trainingFinished = true; }  @Override void train(List<OrderItem> orderItems, List<Order> orders); @Override List<Long> recommendProducts(Long userid, List<OrderItem> currentItems); Map<Long, Map<Long, Double>> getUserBuyingMatrix(); void setUserBuyingMatrix(Map<Long, Map<Long, Double>> userBuyingMatrix); Set<Long> getTotalProducts(); void setTotalProducts(Set<Long> totalProducts); Map<Long, Set<OrderItemSet>> getUserItemSets(); void setUserItemSets(Map<Long, Set<OrderItemSet>> userItemSets); }
AbstractRecommender implements IRecommender { @Override public void train(List<OrderItem> orderItems, List<Order> orders) { long tic = System.currentTimeMillis(); totalProducts = new HashSet<>(); Map<Long, OrderItemSet> unOrderizeditemSets = new HashMap<>(); for (OrderItem orderItem : orderItems) { if (!unOrderizeditemSets.containsKey(orderItem.getOrderId())) { unOrderizeditemSets.put(orderItem.getOrderId(), new OrderItemSet()); unOrderizeditemSets.get(orderItem.getOrderId()).setOrderId(orderItem.getOrderId()); } unOrderizeditemSets.get(orderItem.getOrderId()).getOrderset().put(orderItem.getProductId(), orderItem.getQuantity()); if (!totalProducts.contains(orderItem.getProductId())) { totalProducts.add(orderItem.getProductId()); } } Map<Order, OrderItemSet> itemSets = new HashMap<>(); for (Long orderid : unOrderizeditemSets.keySet()) { Order realOrder = findOrder(orders, orderid); itemSets.put(realOrder, unOrderizeditemSets.get(orderid)); } userItemSets = new HashMap<>(); for (Order order : itemSets.keySet()) { if (!userItemSets.containsKey(order.getUserId())) { userItemSets.put(order.getUserId(), new HashSet<OrderItemSet>()); } itemSets.get(order).setUserId(order.getUserId()); userItemSets.get(order.getUserId()).add(itemSets.get(order)); } userBuyingMatrix = createUserBuyingMatrix(userItemSets); executePreprocessing(); LOG.info("Training recommender finished. Training took: " + (System.currentTimeMillis() - tic) + "ms."); trainingFinished = true; }  @Override void train(List<OrderItem> orderItems, List<Order> orders); @Override List<Long> recommendProducts(Long userid, List<OrderItem> currentItems); Map<Long, Map<Long, Double>> getUserBuyingMatrix(); void setUserBuyingMatrix(Map<Long, Map<Long, Double>> userBuyingMatrix); Set<Long> getTotalProducts(); void setTotalProducts(Set<Long> totalProducts); Map<Long, Set<OrderItemSet>> getUserItemSets(); void setUserItemSets(Map<Long, Set<OrderItemSet>> userItemSets); static final int MAX_NUMBER_OF_RECOMMENDATIONS; }