视频讲解: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.5base, test = loadData()
FEAT_CATE_NUM = base.shape[1] - 1
K = tf.keras.backenddef run():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()