资源简介

deepFM推荐模型,基于深度学习,内含测试数据和详细代码,可参考

资源截图

代码片段和文件信息

“““
Tensorflow implementation of DeepFM [1]

Reference:
[1] DeepFM: A Factorization-Machine based Neural Network for CTR Prediction
    Huifeng Guo Ruiming Tang Yunming Yey Zhenguo Li Xiuqiang He.
“““

import numpy as np
import tensorflow as tf
from sklearn.base import baseEstimator TransformerMixin
from sklearn.metrics import roc_auc_score
from time import time
from tensorflow.contrib.layers.python.layers import batch_norm as batch_norm
from yellowfin import YFOptimizer


class DeepFM(baseEstimator TransformerMixin):
    def __init__(self feature_size field_size
                 embedding_size=8 dropout_fm=[1.0 1.0]
                 deep_layers=[32 32] dropout_deep=[0.5 0.5 0.5]
                 deep_layers_activation=tf.nn.relu
                 epoch=10 batch_size=256
                 learning_rate=0.001 optimizer_type=“adam“
                 batch_norm=0 batch_norm_decay=0.995
                 verbose=False random_seed=2016
                 use_fm=True use_deep=True
                 loss_type=“logloss“ eval_metric=roc_auc_score
                 l2_reg=0.0 greater_is_better=True):
        assert (use_fm or use_deep)
        assert loss_type in [“logloss“ “mse“] \
            “loss_type can be either ‘logloss‘ for classification task or ‘mse‘ for regression task“

        self.feature_size = feature_size        # denote as M size of the feature dictionary
        self.field_size = field_size            # denote as F size of the feature fields
        self.embedding_size = embedding_size    # denote as K size of the feature embedding

        self.dropout_fm = dropout_fm
        self.deep_layers = deep_layers
        self.dropout_deep = dropout_deep
        self.deep_layers_activation = deep_layers_activation
        self.use_fm = use_fm
        self.use_deep = use_deep
        self.l2_reg = l2_reg

        self.epoch = epoch
        self.batch_size = batch_size
        self.learning_rate = learning_rate
        self.optimizer_type = optimizer_type

        self.batch_norm = batch_norm
        self.batch_norm_decay = batch_norm_decay

        self.verbose = verbose
        self.random_seed = random_seed
        self.loss_type = loss_type
        self.eval_metric = eval_metric
        self.greater_is_better = greater_is_better
        self.train_result self.valid_result = [] []

        self._init_graph()


    def _init_graph(self):
        self.graph = tf.Graph()
        with self.graph.as_default():

            tf.set_random_seed(self.random_seed)

            self.feat_index = tf.placeholder(tf.int32 shape=[None None]
                                                 name=“feat_index“)  # None * F
            self.feat_value = tf.placeholder(tf.float32 shape=[None None]
                                                 name=“feat_value“)  # None * F
            self.label = tf.placeholder(tf.float32 shape=[None 1] name=“label“)  # None * 1
            self.dropout_keep_fm = tf.placeholder(tf.floa

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-04-15 16:11  tensorflow-DeepFM-master\
     目录           0  2019-04-15 16:19  tensorflow-DeepFM-master\.idea\
     文件         138  2019-04-15 16:06  tensorflow-DeepFM-master\.idea\encodings.xml
     文件         321  2019-04-15 16:18  tensorflow-DeepFM-master\.idea\misc.xml
     文件         307  2019-04-15 16:06  tensorflow-DeepFM-master\.idea\modules.xml
     文件         538  2019-04-15 16:18  tensorflow-DeepFM-master\.idea\tensorflow-DeepFM-master.iml
     文件         188  2019-04-15 16:18  tensorflow-DeepFM-master\.idea\vcs.xml
     文件        4917  2019-04-15 16:19  tensorflow-DeepFM-master\.idea\workspace.xml
     文件       18787  2018-06-10 19:09  tensorflow-DeepFM-master\DeepFM.py
     文件        4246  2018-06-10 19:09  tensorflow-DeepFM-master\README.md
     目录           0  2019-04-15 14:20  tensorflow-DeepFM-master\example\
     文件        3348  2018-06-10 19:09  tensorflow-DeepFM-master\example\DataReader.py
     文件         171  2018-06-10 19:09  tensorflow-DeepFM-master\example\README.md
     文件           0  2018-06-10 19:09  tensorflow-DeepFM-master\example\__init__.py
     文件        1398  2018-06-10 19:09  tensorflow-DeepFM-master\example\config.py
     目录           0  2019-04-15 14:28  tensorflow-DeepFM-master\example\data\
     文件         138  2018-06-10 19:09  tensorflow-DeepFM-master\example\data\README.md
     文件    12725557  2017-08-22 04:53  tensorflow-DeepFM-master\example\data\sample_submission.csv
     文件   172006681  2017-08-22 04:53  tensorflow-DeepFM-master\example\data\test.csv
     文件   115852544  2017-08-22 04:53  tensorflow-DeepFM-master\example\data\train.csv
     目录           0  2019-04-15 14:20  tensorflow-DeepFM-master\example\fig\
     文件       56504  2018-06-10 19:09  tensorflow-DeepFM-master\example\fig\DNN.png
     文件       38926  2018-06-10 19:09  tensorflow-DeepFM-master\example\fig\DeepFM.png
     文件       47512  2018-06-10 19:09  tensorflow-DeepFM-master\example\fig\FM.png
     文件        5718  2018-06-10 19:09  tensorflow-DeepFM-master\example\main.py
     文件         462  2018-06-10 19:09  tensorflow-DeepFM-master\example\metrics.py
     目录           0  2019-04-15 14:20  tensorflow-DeepFM-master\example\output\
     文件          29  2018-06-10 19:09  tensorflow-DeepFM-master\example\output\README.md
     目录           0  2019-04-15 16:17  tensorflow-DeepFM-master\venv\
     目录           0  2019-04-16 10:42  tensorflow-DeepFM-master\venv\Include\
     目录           0  2019-04-15 16:11  tensorflow-DeepFM-master\venv\Lib\
............此处省略1135个文件信息

评论

共有 条评论