视频讲解:https://www.yuque.com/chudi/tzqav9/ny150b#aalY8
import tensorflow as tf
from tensorflow import keras
from utils import *
EPOCH = 10
BATCH_SIZE = 32
VEC_DIM = 10
DNN_LAYERS = [64, 128, 64]
DROPOUT_RATE = 0.5
base, test = loadData()
# 所有的特征各个类别值个数之和
FEAT_CATE_NUM = base.shape[1] - 1
K = tf.keras.backend
def run():
# 将所有的特征的各个类别值统一id化。x中每行为各特征的类别值的id
val_x, val_y = getAllData(test)
train_x, train_y = getAllData(base)
model = keras.models.Sequential()
model.add(keras.layers.Embedding(FEAT_CATE_NUM, VEC_DIM, input_length=val_x[0].shape[0]))
model.add(keras.layers.Flatten())
for units in DNN_LAYERS:
model.add(keras.layers.Dense(units, activation='relu'))
model.add(keras.layers.Dropout(DROPOUT_RATE))
model.add(keras.layers.Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer=tf.train.AdamOptimizer(0.001), metrics=[keras.metrics.AUC()])
tbCallBack = keras.callbacks.TensorBoard(log_dir='./logs',
histogram_freq=0,
write_graph=True,
write_grads=True,
write_images=True,
embeddings_freq=0,
embeddings_layer_names=None,
embeddings_metadata=None)
model.fit(train_x, train_y, batch_size=BATCH_SIZE, epochs=EPOCH, verbose=2, validation_data=(val_x, val_y),
callbacks=[tbCallBack])
run()
今天的文章深度推荐模型——FNN [ECIR 16]分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/27944.html