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, validation_split=0.2, callbacks=[logs]) pred_ans = model.predict(test_model_input, batch_size=256)
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) print("test LogLoss", round(log_loss(test[target].values, pred_ans), 4)) print("test AUC", round(roc_auc_score(test[target].values, pred_ans), 4))