前面到拆分数据集都一样,下面是构建模型
1、Wide 模型
input_ = keras.layers.Input(shape = train_features.shape[1:])
hidden1 = keras.layers.Dense(10,activation='selu')(input_)
hidden2 = keras.layers.Dense(5,activation='selu')(hidden1)
concat = keras.layers.Concatenate()([input_, hidden2])
output = keras.layers.Dense(1,activation='sigmoid')(concat)
model_wide = keras.Model(inputs=[input_], outputs=[output])
下面构建模型的损伤函数,然后执行模型的训练操作
2、多输入模型
#拆分数据集
train_features_A = train_features.iloc[:,:5]
train_features_B = train_features.iloc[:,5:]
validation_features_A = validation_features.iloc[:,:5]
validation_features_B = validation_features.iloc[:,5:]
#构建模型
input_A = keras.layers.Input(shape=[5], name="wide_input")
input_B = keras.layers.Input(shape=[8], name="deep_input")
hidden1_ = keras.layers.Dense(5, activation="selu")(input_B)
hidden2_ = keras.layers.Dense(3, activation="selu")(hidden1_)
concat_ = keras.layers.concatenate([input_A, hidden2_])
output_ = keras.layers.Dense(1,activation='sigmoid')(concat_)
model_combine = keras.Model(inputs=[input_A, input_B], outputs=[output_])
model_combine.summary()
然后照样构建模型的损伤函数,然后执行模型的训练操作
如何使用TensorBoard
tensorboard_cb = keras.callbacks.TensorBoard(log_dir='output/logs',histogram_freq=1,embeddings_freq=1)
model_combine.fit((train_features_A, train_features_B),train_target,batch_size = 20, epochs=200,
validation_data=((validation_features_A,validation_features_B), validation_target),
callbacks=tensorboard_cb)
如何查看
打开网址后,下面是模型训练情况:
我们也可以看到模型架构图
以下是代码:
原创文章(本站视频密码:66668888),作者:xujunzju,如若转载,请注明出处:https://zyicu.cn/?p=16577