Tensorflow是目前非常流行的deeplearning框架,学习Tensorflow最好的方法是github上的tf项目https://github.com/tensorflow/tensorflow

或者阅读极客学院主导翻译的中文教程http://wiki.jikexueyuan.com/project/tensorflow-zh/how_tos/reading_data.html 。

  此处对tensorflow的基本语法不予赘述,直接贴上源码:

import numpy as np
import tensorflow as tf

#准备数据
trainX = np.linspace(-1, 1, 101)
trainY = 2 * trainX + np.random.randn(*trainX.shape) * 0.33

#定义模型
def model(X, w):
return tf.mul(X, w)

#初始化数据流图
X = tf.placeholder('float')
Y = tf.placeholder('float') w = tf.Variable(0.0, name = 'weights') y_ = model(X, w) #评估模型
cost = tf.square(Y - y_)
train_op = tf.train.GradientDescentOptimizer(0.01).minimize(cost) sess = tf.InteractiveSession()
init = tf.initialize_all_variables()
#训练
sess.run(init)
for i in range(100):
for (x, y) in zip(trainX, trainY):
sess.run(train_op, feed_dict = {X: x, Y: y})
print sess.run(w) sess.close()

由浅入深之Tensorflow(1)----linear_regression实现的更多相关文章

  1. 由浅入深之Tensorflow(3)----数据读取之TFRecords

    转载自http://blog.csdn.net/u012759136/article/details/52232266 原文作者github地址 概述 关于Tensorflow读取数据,官网给出了三种 ...

  2. 由浅入深之Tensorflow(2)----logic_regression实现

    import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_dat ...

  3. 由浅入深之Tensorflow(4)----Saver&restore

    x = tf.placeholder(tf.float32) y = tf.placeholder(tf.float32) w = tf.Variable(tf.zeros([1, 1], dtype ...

  4. 资源 | 数十种TensorFlow实现案例汇集:代码+笔记

    选自 Github 机器之心编译 参与:吴攀.李亚洲 这是使用 TensorFlow 实现流行的机器学习算法的教程汇集.本汇集的目标是让读者可以轻松通过案例深入 TensorFlow. 这些案例适合那 ...

  5. Tensorflow之卷积神经网络(CNN)

    前馈神经网络的弊端 前一篇文章介绍过MNIST,是采用的前馈神经网络的结构,这种结构有一个很大的弊端,就是提供的样本必须面面俱到,否则就容易出现预测失败.如下图: 同样是在一个图片中找圆形,如果左边为 ...

  6. 数十种TensorFlow实现案例汇集:代码+笔记(转)

    转:https://www.jiqizhixin.com/articles/30dc6dd9-39cd-406b-9f9e-041f5cbf1d14 这是使用 TensorFlow 实现流行的机器学习 ...

  7. tensorflow 经典教程及案例

    导语:本文是TensorFlow实现流行机器学习算法的教程汇集,目标是让读者可以轻松通过清晰简明的案例深入了解 TensorFlow.这些案例适合那些想要实现一些 TensorFlow 案例的初学者. ...

  8. TensorFlow中的通信机制——Rendezvous(一)本地传输

    背景 [作者:DeepLearningStack,阿里巴巴算法工程师,开源TensorFlow Contributor] 在TensorFlow源码中我们经常能看到一个奇怪的词——Rendezvous ...

  9. AI学习---基于TensorFlow的案例[实现线性回归的训练]

    线性回归原理复习 1)构建模型               |_> y = w1x1 + w2x2 + -- + wnxn + b        2)构造损失函数               | ...

随机推荐

  1. 杭电 1280 前m大的数

    http://acm.hdu.edu.cn/showproblem.php?pid=1280 前m大的数 Time Limit: 2000/1000 MS (Java/Others)    Memor ...

  2. js修改剪切板内容的方法

    代码如下: //绑定在了body上,也可以绑定在其他可用元素行,但是不是所有元素都支持copy事件. $(document.body).bind({ copy: function(e) {//copy ...

  3. DistroWatch评估XStream桌面153版本

    导读 XStreamOS是一个由Sonicle创建的Solaris的一个版本.XStream桌面将Solaris的强大带给了桌面用户,同时新手用户很可能有兴趣体验一下.DistroWatch对于XSt ...

  4. webpack配置(二)

    在配置webpack json loader的时候报错,如下: 解决方案: 首先,json文件中不能有注释 其次: 这里webpack.consig.js里面,modul下的loaders的loade ...

  5. excel 使用技巧

    计算两个日期的差值 1.计算当前日期与目标日期相差天数,下面例子中当前日期未2017/3/19 2.列增加数据条

  6. 160328、rabbitMQ集群部署示例

    环境:Centos 6.5 x86_64MQ网址:http://www.rabbitmq.com/SERVER101\SERVER102 SERVER103 一.单节点安装 #yum install ...

  7. HDU 5876 大连网络赛 Sparse Graph

    Sparse Graph Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) T ...

  8. CodeForces 24B F1 Champions(排序)

    B. F1 Champions time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. POJ 3735 Training little cats(矩阵快速幂)

    Training little cats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11787 Accepted: 2892 ...

  10. 让IIS8支持WCF的最简单方法

    以前在IIS8中使用WCF时,总是参考在IIS8添加WCF服务支持这篇博文进行手工设置: 1. 首先添加MIME类型:扩展名“.svc”,MIME类型 “application/octet-strea ...