tensorflow

1.一切都要tf.

2.只有sess.run才能生效

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt ######################################################
#data
nump_points=1000
vector_set=[]
for i in range(nump_points):
x1=np.random.normal(0.0,0.55)
y1=x1*0.1+0.3+np.random.normal(0.0,0.03)
vector_set.append([x1,y1]) x_data=[v[0] for v in vector_set]
y_data=[v[1] for v in vector_set] plt.scatter(x_data,y_data,c='r')
plt.show()
########################################################
#linear regression
#y=wx+b,initial value
w=tf.Variable(tf.random_uniform([1],-1.0,1.0),name='w')
b=tf.Variable(tf.zeros([1]))
#model
y=w*x_data+b
#trainer set up
loss=tf.reduce_mean(tf.square(y-y_data))
optimizer=tf.train.GradientDescentOptimizer(0.5)
train=optimizer.minimize(loss) sess=tf.Session()
init=tf.global_variables_initializer()
sess.run(init)
#first step
print('w=',sess.run(w),'b=',"loss:",sess.run(loss))
for step in range(20):
sess.run(train)
print('w=', sess.run(w), 'b=', "loss:", sess.run(loss))

1.tensorflow——线性回归的更多相关文章

  1. [tensorflow] 线性回归模型实现

    在这一篇博客中大概讲一下用tensorflow如何实现一个简单的线性回归模型,其中就可能涉及到一些tensorflow的基本概念和操作,然后因为我只是入门了点tensorflow,所以我只能对部分代码 ...

  2. python,tensorflow线性回归Django网页显示Gif动态图

    1.工程组成 2.urls.py """Django_machine_learning_linear_regression URL Configuration The ` ...

  3. tensorflow 线性回归解决 iris 2分类

    # Combining Everything Together #---------------------------------- # This file will perform binary ...

  4. TensorFlow线性回归

    目录 数据可视化 梯度下降 结果可视化 数据可视化 import numpy as np import tensorflow as tf import matplotlib.pyplot as plt ...

  5. tensorflow 线性回归 iris

    线性拟合

  6. TensorFlow简要教程及线性回归算法示例

    TensorFlow是谷歌推出的深度学习平台,目前在各大深度学习平台中使用的最广泛. 一.安装命令 pip3 install -U tensorflow --default-timeout=1800 ...

  7. TensorFlow API 汉化

    TensorFlow API 汉化 模块:tf   定义于tensorflow/__init__.py. 将所有公共TensorFlow接口引入此模块. 模块 app module:通用入口点脚本. ...

  8. tfboys——tensorflow模块学习(三)

    tf.estimator模块 定义在:tensorflow/python/estimator/estimator_lib.py 估算器(Estimator): 用于处理模型的高级工具. 主要模块 ex ...

  9. TensorFlow — 相关 API

    TensorFlow — 相关 API TensorFlow 相关函数理解 任务时间:时间未知 tf.truncated_normal truncated_normal( shape, mean=0. ...

随机推荐

  1. R语言利用ROCR评测模型的预测能力

    R语言利用ROCR评测模型的预测能力 说明 受试者工作特征曲线(ROC),这是一种常用的二元分类系统性能展示图形,在曲线上分别标注了不同切点的真正率与假正率.我们通常会基于ROC曲线计算处于曲线下方的 ...

  2. Git 内部原理

    首先要弄明白一点,从根本上来讲 Git 是一个内容寻址(content-addressable)文件系统,并在此之上提供了一个版本控制系统的用户界面. 马上你就会学到这意味着什么. git objec ...

  3. shell cp拷贝的用法

    个人觉得这个记录的比较全 自己查阅: cp [options] <source file or directory> <target file or directory> 或 ...

  4. 将QTP运行时的错误截图上传到QC

    Class QCImageErrorCapture Sub Class_Terminate() 'Check if the current test has failed. If failed the ...

  5. Scapy——Scrapy shell的使用

    在开发爬虫的使用,scrapy shell可以帮助我们定位需要爬取的资源 启动Scrapy Shell 在终端中输入以下内容即可启动scrapy shell,其中url是要爬取的页面,可以不设置 sc ...

  6. 各种Web服务器与Nginx的对比

    Tomcat和Jetty面向Java语言,先天就是重量级的Web服务器,它们的性能与Nginx没有可比性. IIS只能在windows操作系统上运行,Windows作为服务器在稳定性与其他一些性能上都 ...

  7. 构建一个简单的Spring Boot项目

    11 构建一个简单的Spring Boot项目 这个章节描述如何通过Spring Boot构建一个"Hello Word"web应用,侧重介绍Spring Boot的一些重要功能. ...

  8. FZU 1876 JinYueTuan(排列组合)

    Description Let’s have a look at the picture below Now, do you know what it’s? Yeah , O(∩_∩)O~ , It ...

  9. 40.Unique Binary Search Trees(不同的二叉搜索树)

    Level:   Medium 题目描述: Given n, how many structurally unique BST's (binary search trees) that store v ...

  10. IE的debug工具对程序进行debug跟踪JS代码

    2015/8/31 (其他的:显示zjfy_app_sys_ip.html,只需关闭启用保护模式) 显示ie的debug,F12-->Ctrl + P 扩展:第一步,在程序中设置断点,如图所示左 ...