3.1 configuration
3.2 寻找最优网络参数
代码示例:
from keras.models import Sequential
from keras.layers import Dense, Activation
# 1.Step 1
model = Sequential()
model.add(Dense(input_dim=28*28, output_dim=500)) # Dense是全连接
model.add(Activation('sigmoid'))
model.add(Dense(output_dim=500))
model.add(Activation('sigmoid'))
model.add(Dense(output_dim=10))
model.add(Activation('softmax'))
# Step 2
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
# Step 3
model.fit(x_train, y_train, batch_size=100, nb_epoch=20)
# 模型保存
#case1:测试集正确率
score = model.evaluate(x_test,y_test)
print("Total loss on Testing Set:", score[0])
print("Accuracy of Testing Set:", score[1])
#case2:模型预测
result = model.predict(x_test)
x_train, y_train解释
小批量梯度下降,速度更快的原因是因为可以并行计算。