我是靠谱客的博主 自信大侠,这篇文章主要介绍Tensorflow 使用 Gradient Descent(梯度下降) 分析 Linear Regression(线性回归),现在分享给大家,希望可以做个参考。

# _*_ coding:UTF-8 _*_
#引入相关依赖
import tensorflow as tf
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np

plot_num = 100
vectors= []
#模拟原始数据
for i in range(plot_num):
    x1 = np.random.normal(0,0.66)
    y1 = 0.1 * x1 + 0.2 + np.random.normal(0,0.04)
    vectors.append([x1,y1])

x_data = [v[0] for v in vectors]

y_data = [v[1] for v in vectors]

#画出原始点图

plt.plot(x_data,y_data,'r*',label='Original data')
plt.title('Linear Regression using Gradient Descent')
plt.legend()
plt.savefig('./file.png',dpi=150)

#构建线性回归模型
W = tf.Variable(tf.random_uniform([1],-1.0,1.0))
b = tf.Variable(tf.zeros(1))
y = W * x_data + b


#定义损失函数
loss = tf.reduce_mean(tf.squ

最后

以上就是自信大侠最近收集整理的关于Tensorflow 使用 Gradient Descent(梯度下降) 分析 Linear Regression(线性回归)的全部内容,更多相关Tensorflow内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部