03_04 toy_problem

import numpy as np
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.optimizers import SGD
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.utils import shuffle

np.random.seed(0)

N = 300
X, y = datasets.make_moons(N, noise=0.3)
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.8)

model = Sequential()
model.add(Dense(3, input_dim=2))
model.add(Activation('sigmoid'))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer=SGD(lr=0.05),
metrics=['accuracy'])

model.fit(X_train, y_train, epochs=500, batch_size=20)

loss_and_metrics = model.evaluate(X_test, y_test)
print(loss_and_metrics)


60/60 [==============================] - 0s 551us/step
[0.250763734181722, 0.8833333214124044]



阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页