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]



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

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试