三木社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 295|回复: 0
打印 上一主题 下一主题

Hello World

[复制链接]

1562

主题

1564

帖子

4904

积分

博士

Rank: 8Rank: 8

积分
4904
跳转到指定楼层
楼主
发表于 2017-9-18 07:41:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. import tensorflow as tf
  2. import numpy as np

  3. # Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
  4. x_data = np.random.rand(100).astype(np.float32)
  5. y_data = x_data * 0.1 + 0.3

  6. # Try to find values for W and b that compute y_data = W * x_data + b
  7. # (We know that W should be 0.1 and b 0.3, but TensorFlow will
  8. # figure that out for us.)
  9. W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
  10. b = tf.Variable(tf.zeros([1]))
  11. y = W * x_data + b

  12. # Minimize the mean squared errors.
  13. loss = tf.reduce_mean(tf.square(y - y_data))
  14. optimizer = tf.train.GradientDescentOptimizer(0.5)
  15. train = optimizer.minimize(loss)

  16. # Before starting, initialize the variables.  We will 'run' this first.
  17. init = tf.global_variables_initializer()

  18. # Launch the graph.
  19. sess = tf.Session()
  20. sess.run(init)

  21. # Fit the line.
  22. for step in range(201):
  23.     sess.run(train)
  24.     if step % 20 == 0:
  25.         print(step, sess.run(W), sess.run(b))

  26. # Learns best fit is W: [0.1], b: [0.3]
复制代码


回复

使用道具 举报

Archiver|手机版|小黑屋|三木电子社区 ( 辽ICP备11000133号-4 )

辽公网安备 21021702000620号

GMT+8, 2025-5-9 23:56 , Processed in 0.028933 second(s), 22 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表