python:ai:tensorflow第一课实例:正负数判断

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

model= Sequential()
model.add(Dense(units=8,activation='relu',input_dim=1))
model.add(Dense(units=1,activation='sigmoid'))
model.compile (loss='mean_squared_error', optimizer='sgd')

x=[1,2,3,10,20,-2,-10,-100,-5,-20]
y=[1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0]
model.fit(x, y, epochs=10, batch_size=4)

test_x=[30,40,-20,-60]
test_y= model.predict(test_x)

for i in range(0, len(test_x)):
    print('input {}=> predict: {} '.format (test_x[i], test_y[i]))
Epoch 1/10
3/3 [==============================] - 0s 667us/step - loss: 0.0437
Epoch 2/10
3/3 [==============================] - 0s 333us/step - loss: 0.0434
Epoch 3/10
3/3 [==============================] - 0s 667us/step - loss: 0.0430
Epoch 4/10
3/3 [==============================] - 0s 333us/step - loss: 0.0426
Epoch 5/10
3/3 [==============================] - 0s 667us/step - loss: 0.0423
Epoch 6/10
3/3 [==============================] - 0s 333us/step - loss: 0.0420
Epoch 7/10
3/3 [==============================] - 0s 333us/step - loss: 0.0416
Epoch 8/10
3/3 [==============================] - 0s 333us/step - loss: 0.0413
Epoch 9/10
3/3 [==============================] - 0s 667us/step - loss: 0.0410
Epoch 10/10
3/3 [==============================] - 0s 333us/step - loss: 0.0408
input 30=> predict: [1.] 
input 40=> predict: [1.] 
input -20=> predict: [0.00450122] 
input -60=> predict: [9.23217e-08] 

进程已结束,退出代码 0

 

上一篇:【k8s】deploy-Recreate


下一篇:用Keras实现MNIST手写数字识别(使用MLP:多层感知机)