我搭建的第一个神经网络

import numpy as np
import tensorflow as tf
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data*0.1 + 0.3

Weight = tf.Variable(tf.random_uniform([1],-1.0, 1.0))
biases = tf.Variable(tf.zeros([1]))

y = x_data*Weight + biases

loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

init = tf.initialize_all_variables()

sess = tf.Session()
sess.run(init)

for i in range(201):
    sess.run(train)
    if i % 10 == 0:
        print(i, sess.run(Weight), sess.run(biases))
0 [0.5913683] [0.02325284]
10 [0.33041072] [0.17002238]
20 [0.20808482] [0.23902799]
30 [0.1507022] [0.27139825]
40 [0.12378422] [0.28658304]
50 [0.1111571] [0.29370615]
60 [0.10523375] [0.2970476]
70 [0.10245514] [0.29861504]
80 [0.1011517] [0.29935032]
90 [0.10054026] [0.29969525]
100 [0.10025343] [0.29985705]
110 [0.10011888] [0.29993296]
120 [0.10005578] [0.29996854]
130 [0.10002616] [0.29998526]
140 [0.10001229] [0.2999931]
150 [0.10000578] [0.29999676]
160 [0.10000271] [0.2999985]
170 [0.10000128] [0.2999993]
180 [0.1000006] [0.29999968]
190 [0.10000029] [0.29999986]
200 [0.10000014] [0.29999995]

Process finished with exit code 0

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值