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 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)
train = optimizer.minimize(loss)
init = tf.initialize_all_variables() 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.7417692] [-0.07732911]
20 [0.30772722] [0.18689097]
40 [0.16603212] [0.26404503]
60 [0.12099022] [0.28857067]
80 [0.10667235] [0.29636687]
100 [0.10212099] [0.2988451]
120 [0.10067423] [0.29963288]
140 [0.10021434] [0.2998833]
160 [0.10006816] [0.2999629]
180 [0.10002167] [0.2999882]
200 [0.10000689] [0.29999626]

  

TensorFlow1.0 线性回归的更多相关文章

  1. Ubuntu14.10安装TensorFlow1.0.1

    本文记录了在Ubuntu上安装TensorFlow的步骤.系统环境:Ubuntu14.10 64bitPython版本:Python 2.7.8TensorFlow版:TensorFlow 1.0.1 ...

  2. 初用Linux, 安装Ubuntu16.04+NVIDIA387+CUDA8.0+cudnn5.1+TensorFlow1.0.1

    因为最近Deep Learning十分热门, 装一下TensorFlow学习一下. 本文主要介绍安装流程, 将自己遇到的问题说明出来, 并记录自己如何处理, 原理方面并没有能力解释. 由于本人之前从来 ...

  3. tensorflow1.0.0 弃用了几个operator写法

    除法和取模运算符(/, //, %)现已匹配 Python(flooring)语义.这也适用于 tf.div 和 tf.mod.为了获取强制的基于整数截断的行为,你可以使用 tf.truncatedi ...

  4. tensorflow1.0中的改善

    TensorFlow 1.0 重大功能及改善 XLA(实验版):初始版本的XLA,针对TensorFlow图(graph)的专用编译器,面向CPU和GPU. TensorFlow Debugger(t ...

  5. tensorflow1.0 队列FIFOQueue管理实现异步读取训练

    import tensorflow as tf #模拟异步子线程 存入样本, 主线程 读取样本 # 1. 定义一个队列,1000 Q = tf.FIFOQueue(1000,tf.float32) # ...

  6. tensorflow1.0 数据队列FIFOQueue的使用

    import tensorflow as tf #模拟一下同步先处理数据,然后才能取数据训练 #tensorflow当中,运行操作有依赖性 #1.首先定义队列 Q = tf.FIFOQueue(3,t ...

  7. tensorflow1.0 lstm学习曲线

    import tensorflow as tf import numpy as np import matplotlib.pyplot as plt BATCH_START = 0 TIME_STEP ...

  8. tensorflow1.0 构建lstm做图片分类

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #this is data mni ...

  9. tensorflow1.0 dropout层

    """ Please note, this code is only for python 3+. If you are using python 2+, please ...

随机推荐

  1. WeChat-SmallProgram:组件的业务 slot 的使用

    1.调用组件向自定义组件插入内容,使用  slot 在自定义模板中有一对 <view><slot></slot></view> 这里是干什么用的呢? 在 ...

  2. js原生模拟new 关键字

    function newOperator(ctor){ if(typeof ctor !== 'function'){ throw 'newOperator function the first pa ...

  3. nginx IF 指令

    变量名可以使用"="或"!="运算符 ~ 符号表示区分大小写字母的匹配 "~*"符号表示不区分大小写字母的匹配 "!"和 ...

  4. Git之旅

    ithub安装,我选择的是windows下的版本. git配置用户信息 安装完成后,还需要最后一步设置,在命令行输入: $git config --global user.name "You ...

  5. python学习第二节 数据类型、字符编码、文件处理

    标准数据类型 Python3 中有六个标准的数据类型: Number(数字) String(字符串) List(列表) Tuple(元组) Sets(集合) Dictionary(字典) 数字 #整型 ...

  6. ArrayList源码浅析

    这里只理解主要的常用方法: 1 public class ArrayList<E> extends AbstractList<E> 2 implements List<E ...

  7. 在ES5实现ES6中的Object.is方法

    ES6中对象的扩展里面添加了一个Object.is方法,用于比较两个值是否严格相等.内部计算与 === 行为基本一致.那么我们怎么在不支持这个方法的ES5中实现呢? 首先我们需要搞清楚两点,1:Obj ...

  8. CAS / ABA

    CAS / ABA 标签(空格分隔): 操作系统 1. CAS 解决 Volatile 不保证原子性的问题 /** * Atomically increments by one the current ...

  9. 《Three.js 入门指南》1.3 - Three JS 功能预览

    [部分中英文对照] Cameras(照相机,控制投影方式) Camera OrthographicCamera 正交相机 PerspectiveCamera 透视相机 Core(核心对象) Buffe ...

  10. Haystack+ES解决搜索服务

    最近项目组需要对老的搜索项目进行迁移和改造,刚入职2个星期的我光荣的接受了这份工作,这也是我第一次接触Haystack和Elasticsearch,以下是记录下工作中的一些需求解决,具体haystac ...