Giter Site home page Giter Site logo

grocery's Introduction

Grocery

This repo includes python/tensorflow implementations of several algorithms proposed for modeling grocery shopping behavior.

These alogrithms have been implemented

  • the product representation learning model -- triple2vec
  • the incremental module -- adaLoyal for next-basket recommendations

both proposed in

Mengting Wan, Di Wang, Jie Liu, Paul Bennett, Julian McAuley, "Representing and Recommending Shopping Baskets with Complementarity, Compatibility, and Loyalty", in CIKM'18 [bibtex]

Algorithms proposed in

Mengting Wan, Di Wang, Matt Goldman, Matt Taddy, Justin Rao, Jie Liu, Dimitrios Lymberopoulos, Julian McAuley, "Modeling Consumer Preferences and Price Sensitivities from Large-Scale Grocery Shopping Transaction Logs", in WWW'17 [bibtex]

will be added in the future.

If you would like to extend or compare with our algorithms, or use our source code, please consider citing the above two papers.

Any questions feel free to contact Mengting Wan ([email protected]).

Quick Start

Requirement:

  • Python 3.6+ (older version has not been tested)
  • Tensorflow 1.6.0+ (older version has not been tested)

Quick start with a subset of Instacart for triple2vec and adaLoyal

  • Please first download the complete dataset from here and release the files under ./data/. This is a relatively large dataset which includes more than 3 million orders. We could start with a small subset of users to test the algorithms instantly.

  • Preprocess the dataset

python ./src/parser.py --data_name instacart --thr_item 10 --thr_user 0 --subset_user 0.1

This will randomly sample transactions associated with 10% users and filter out products with <10 transactions. Please consider adjusting these thresholds if you plan to run the algorithms on the complete dataset.

The processed files will be saved as

  • ./data/instacart.data.csv: csv file which can be read by pandas and must include the following columns: UID(integers used to represent user IDs), PID(a list of integers to represent product IDs in the current transaction), flag(train, validation or test). Each row represents each transaction/basket record.

  • ./data/instacart.meta.csv: csv file which can be read by pandas, including meta-data of products.

    Note: In order to run adaLoyal, transactions in this file need to be sorted in chronological order.

    Note: In order to run triple2vec, product IDs need to be sorted based on their popularities (i.e., PID=0 represents the most popular product). This will boost the negative sampling process in the noise contrastive estimation loss functions applied in representation learning algorithms.

  • Run triple2vec

python ./src/main.py --data_name instacart --mode embedding --method_name triple2vec --dim 32 --lr 1.0 --batch_size 1000 --n_neg 5

This will first generate training samples and cache it under ./output/sample/ (optional). Then product and user embeddings will be dumped under ./output/param/.

  • Run personalized recommendation using item/user generated from triple2vec

python ./src/main.py --data_name instacart --mode recommendation --method_name triple2vec --dim 32 --lr 1.0 --batch_size 1000 --n_neg 5

  • Run personalized recommendation using item/user generated from triple2vec and apply adaLoyal

python ./src/main.py --data_name instacart --mode recommendation --method_name triple2vec --dim 32 --lr 1.0 --batch_size 1000 --n_neg 5 --l0 0.8

where the initial loyalty is set as l0=0.8.

All results will be saved under ./output/result/.

We can also test some simple baselines on this dataset

  • rank products based on their overall popularities in the training set

python ./src/main.py --data_name instacart --mode recommendation --method_name popRec

  • rank products based on user-wise item purchase frequency

python ./src/main.py --data_name instacart --mode recommendation --method_name popRec

How to apply adaLoyal on top of user/product representations from other models?

Ad-hoc needs can be added in this module ./src/recommendation/recommender.py.

TO-DO

  • Implement within-basket recommendation
  • Complete documentation
  • Implement price sensitivities

grocery's People

Contributors

mengtingwan avatar

Watchers

Mindaugas Zickus avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.