mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
31 lines
910 B
Python
31 lines
910 B
Python
# https://keras.io/getting-started/sequential-model-guide/
|
|
# MLP for binary classification
|
|
# 用于二进制分类的MLP
|
|
|
|
import numpy as np
|
|
from tensorflow import keras
|
|
from tensorflow.keras.models import Sequential
|
|
from tensorflow.keras.layers import Dense, Dropout
|
|
|
|
# Generate dummy data
|
|
x_train = np.random.random((1000, 20))
|
|
y_train = np.random.randint(2, size=(1000, 1))
|
|
x_test = np.random.random((100, 20))
|
|
y_test = np.random.randint(2, size=(100, 1))
|
|
|
|
model = Sequential()
|
|
model.add(Dense(64, input_dim=20, activation='relu'))
|
|
model.add(Dropout(0.5))
|
|
model.add(Dense(64, activation='relu'))
|
|
model.add(Dropout(0.5))
|
|
model.add(Dense(1, activation='sigmoid'))
|
|
|
|
model.compile(loss='binary_crossentropy',
|
|
optimizer='rmsprop',
|
|
metrics=['accuracy'])
|
|
|
|
model.fit(x_train, y_train,
|
|
epochs=20,
|
|
batch_size=128)
|
|
score = model.evaluate(x_test, y_test, batch_size=128)
|