Coder Social home page Coder Social logo

deepctr's Introduction

DeepCTR

This project implements serval models of the papers on CTR prediction with easy-to-use call interfaces.

The goal is to make it possible for everyone to use complex models with model.fit()andmodel.predict().

Most of the models have been finished in keras. The tensorflow version will be added soon~ Please feel free to contact me if you have any questions!!

Support Model List

Model Paper Available Framework
AFM [IJCAI 2017]Attentional Factorization Machines: Learning the Weight of Feature Interactions via Attention Networks keras
DCN [ADKDD 2017]Deep & Cross Network for Ad Click Predictions keras,tensorflow
DeepFM [IJCAI 2017]DeepFM: A Factorization-Machine based Neural Network for CTR Prediction keras,tensorflow
MLR [arxiv 2017]Learning Piece-wise Linear Models from Large Scale Data for Ad Click Prediction keras,
NFM [SIGIR 2017]Neural Factorization Machines for Sparse Predictive Analytics keras

Keras Model

Requirements

  • python3
  • tensorflow==1.4.0
  • keras==2.1.2

Quick Start

Source code keras_demo.py

data = pd.read_pickle("./demo/small_data.pkl")
sparse_features = [ "movie_id","user_id","gender","age","occupation","zip"]
target = ['rating']
#1.Label Encoding for sparse features,and Normalization for dense fetures
for feat in sparse_features:
  lbe = LabelEncoder()
  data[feat] = lbe.fit_transform(data[feat])
#2.count #unique features for each sparse field
sparse_feature_dim = {feat:data[feat].nunique() for feat in sparse_features}
#3.generate input data for model
model_input = [data[feat].values for feat in sparse_feature_dim] 
#4.Define Model,compile and train
model = NFM({"sparse":sparse_feature_dim,"dense":[]},final_activation='linear').model

model.compile("adam","mse",metrics=['mse'],)
history = model.fit(model_input,data[target],
        batch_size=256,epochs=5,verbose=2,validation_split=0.2,)

TensorFlow Model

Requirements

  • python3
  • tensorflow==1.4.0
  • numpy==1.13.3
  • scikit-learn==0.19.1

Design Notes

The base base class mimics the keras model to implement the following public methods, including:

  • compile
  • save_model
  • load_mdel
  • train_on_batch
  • fit
  • test_on_batch
  • evaluate
  • predict_on_batch
  • predict

private methods:

  • _create_optimizer
  • _create_metrics
  • _compute_sample_weight

At the same time, several abstract methods are designed:

  • _get_input_data
  • _get_input_target
  • _get_output_target
  • _get_optimizer_loss
  • _build_graph

The subclass is required to call self._build_graph() at the end of the __init__ method to build the calculation graph.

TODO

  • Add tf.summary.FileWriter
  • Add custom metric function
  • Add weighted loss function
  • Encapsulate models with tf.estimator

Quick Start

Source code tf_demo.py

Experiment Result

see docs/README.md

deepctr's People

Contributors

shenweichen avatar

Watchers

 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.