How to create a simple fully connected neural network in Keras?
In Keras, you can create a simple fully connected neural network using the Sequential model. Here is an example:
from keras.models import Sequential
from keras.layers import Dense
# 创建一个Sequential模型
model = Sequential()
# 添加输入层和隐藏层
model.add(Dense(units=64, activation='relu', input_dim=100))
# 添加输出层
model.add(Dense(units=10, activation='softmax'))
# 编译模型
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
# 训练模型
model.fit(X_train, y_train, epochs=10, batch_size=32)
In this example, we have constructed a fully connected neural network with an input layer, a hidden layer with 64 neurons using ReLU activation function, and an output layer with 10 neurons using softmax activation function. The input layer consists of 100 features. We compiled the model using adam optimizer and cross-entropy loss function, and trained the model for 10 epochs.