day7 python学习笔记 tensorflow

【莫凡】
  预测 y=0.1x+0.3

# -*- coding: utf-8 -*-
"""
Created on Thu May 10 15:52:58 2018

@author: sun_y
"""

import tensorflow as tf
import numpy as np

#create data
x_data=np.random.rand(100).astype(np.float32)
y_data=x_data*0.1+0.3

#create tensorflow structure statr###
Weights = tf.Variable(tf.random_uniform([1],-1.0,1.0)) # 一维,用随机数列生成
biases=tf.Variable(tf.zeros([1]))

y=Weights*x_data+biases
loss=tf.reduce_mean(tf.square(y-y_data))
optimizer=tf.train.GradientDescentOptimizer(0.5) #learning rate is 0.5
train=optimizer.minimize(loss)

init=tf.initialize_all_variables()

### create tensorflow structure end###

sess = tf.Session()
sess.run(init)     #激活神经网络

for step in range(201):
    sess.run(train)
    if step % 20 ==0:
        print(step,sess.run(Weights),sess.run(biases))

0 [0.48835528] [0.12029712]
20 [0.19531727] [0.24877861]
40 [0.12414611] [0.28702444]
60 [0.10611676] [0.296713]
80 [0.10154952] [0.29916734]
100 [0.10039254] [0.29978907]
120 [0.10009944] [0.29994658]
140 [0.1000252] [0.29998648]
160 [0.10000637] [0.29999658]
180 [0.10000161] [0.29999915]
200 [0.10000043] [0.29999977]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值