《程序员的AI书_从代码开始》第一章 机器学习的Hello World

1.3 从代码开始
1.3.2 一段简单的代码

python导入tensflow.keras报错解决方法

import tensorflow as tf
from tensorflow.python.keras.models import Sequential
from tensorflow.python.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]))

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/GQ_Sonofgod/article/details/131463195