当前位置:网站首页>1、 Construction of single neural network

1、 Construction of single neural network

2022-06-25 08:51:00 Beyond proverb

One 、 I use the compiler for Jupyter Notebook,tensorflow Version is 1.13.1

import tensorflow as tf
print(tf.__version__)
""" 1.13.1 """

Two 、 Train a single neural network

x by -1.0, 0.0, 1.0, 2.0, 3.0, 4.0
y by -3.0, -1.0, 1.0, 3.0, 5.0, 7.0
It's easy to see with the brain y=2*x-1, Here we build a single neuron model to predict x=10.0 when ,y Value , The theory should be 19, Let's take a look at the performance of the model

from tensorflow import keras
import numpy as np

model = keras.Sequential([keras.layers.Dense(units=1,input_shape=[1])])
model.compile(optimizer='sgd',loss='mean_squared_error')

x = np.array([-1.0,0.0,1.0,2.0,3.0,4.0],dtype=float)
y = np.array([-3.0,-1.0,1.0,3.0,5.0,7.0],dtype=float)

model.fit(x,y,epochs=1000)

model.predict([10.0])
""" array([[18.999922]], dtype=float32) """

Final model training 1000 Time , The predicted result is 18.999922, And the actual real value 19 The difference is not too big

原网站

版权声明
本文为[Beyond proverb]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250755452447.html

随机推荐