Mult Perceptron (MLP) for multi-class softmax classification:
from keras.models import Sequentialfrom keras. s import Dense, Dropout, Activationfrom keras.optimizers import SGD# 生成随机数据import numpy as npx_train = np.random.random((1000, 20))y_train = keras.utils.to_categorical(np.random.randint(10, size=(1000, 1)), num_classes=10)x_test = np.random.random((100, 20))y_test = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)model = Sequential()# Dense(64) is a fully-connected with 64 hidden units.# in the first , you must specify the expected input data shape:# here, 20-dimensional vectors.model.add(Dense(64, activation='relu', input_dim=20))model.add(Dropout(0.5))model.add(Dense(64, activation='relu'))model.add(Dropout(0.5))model.add(Dense(10, activation='softmax'))sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])model.fit(x_train, y_train, epochs=20, batch_size=128)score = model.evaluate(x_test, y_test, batch_size=128)继续阅读与本文标签相同的文章
-
TensorFlow 一步一步实现卷积神经网络
2026-05-26栏目: 教程
-
TensorFlow 卷积神经网络手写数字识别数据集介绍
2026-05-26栏目: 教程
-
深度学习之激活函数
2026-05-26栏目: 教程
-
计算智能(CI)之粒子群优化算法(PSO)(一)
2026-05-26栏目: 教程
-
Tensorflow 介绍和安装
2026-05-26栏目: 教程
