def test_DeepFM(hidden_size, sparse_feature_num): model_name = "FLEN" sample_size = SAMPLE_SIZE x, y, feature_columns = get_test_data(sample_size, embedding_size=2,sparse_feature_num=sparse_feature_num, dense_feature_num=sparse_feature_num,use_group=True) model = FLEN(feature_columns,feature_columns, dnn_hidden_units=hidden_size, dnn_dropout=0.5) check_model(model, model_name, x, y)
dnn_feature_columns = fixlen_feature_columns linear_feature_columns = fixlen_feature_columns feature_names = get_feature_names(linear_feature_columns + dnn_feature_columns) # 3.generate input data for model # train, test = train_test_split(data, test_size=0.2) train = data train_model_input = {name: train[name] for name in feature_names} test_model_input = {name: test[name] for name in feature_names} # 4.Define Model,train,predict and evaluate model = FLEN(linear_feature_columns, dnn_feature_columns, task='binary', dnn_dropout=dropout, dnn_use_bn=True) model.compile(optimizer, "binary_crossentropy", metrics=METRICS) log_dir = prefix_dir + 'flen_' + data_type + '_' + str(epochs) if not os.path.exists(log_dir): # 如果路径不存在 os.makedirs(log_dir) logs = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1) history = model.fit(train_model_input, train[target].values, batch_size=256, epochs=epochs, verbose=2,
] dnn_feature_columns = fixlen_feature_columns linear_feature_columns = fixlen_feature_columns feature_names = get_feature_names(linear_feature_columns + dnn_feature_columns) # 3.generate input data for model train, test = train_test_split(data, test_size=0.2) train_model_input = {name: train[name] for name in feature_names} test_model_input = {name: test[name] for name in feature_names} # 4.Define Model,train,predict and evaluate model = FLEN(linear_feature_columns, dnn_feature_columns, task='binary') model.compile( "adam", "binary_crossentropy", metrics=['binary_crossentropy'], ) history = model.fit( train_model_input, train[target].values, batch_size=256, epochs=10, verbose=2, validation_split=0.2, ) pred_ans = model.predict(test_model_input, batch_size=256)