博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
由浅入深之Tensorflow(1)----linear_regression实现
阅读量:4553 次
发布时间:2019-06-08

本文共 788 字,大约阅读时间需要 2 分钟。

  Tensorflow是目前非常流行的deeplearning框架,学习Tensorflow最好的方法是github上的tf项目

或者阅读极客学院主导翻译的中文教程 。

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

import numpy as npimport 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()

 

转载于:https://www.cnblogs.com/upright/p/6136193.html

你可能感兴趣的文章
ActiveMQ 即时通讯服务 浅析
查看>>
gsoap开发webservice
查看>>
LCA || BZOJ 1602: [Usaco2008 Oct]牧场行走 || Luogu P2912 [USACO08OCT]牧场散步Pasture Walking
查看>>
预处理
查看>>
[php] 使用IDE的正则搜索代码
查看>>
大型网站架构与分布式架构
查看>>
趣图:后端工程师是怎样调试CSS的
查看>>
SQL总结
查看>>
python 基础语法
查看>>
AjaxPro使用中遇到的问题之一
查看>>
集合(NSArray,Set,NSMutableArray,NSDictionary)
查看>>
Sum Root to Leaf Numbers
查看>>
Windows Server: 将虚拟机迁移到 Azure (以阿里云为例)
查看>>
C#实现身份证号码验证的方法
查看>>
docker swarm集群
查看>>
docker 部署jar包
查看>>
在Nginx容器安装Keepalived后端项目双机热备
查看>>
Docker打包部署前端项目与负载均衡
查看>>
一款阿里开源的 Java 诊断工具
查看>>
阿里云云盾安全事件提醒:挖矿程序
查看>>