Tensorflow实现线性回归模型

一,构造数据

引入所需要的函数库,令w=0.5,b=0.3 再加上一些高斯随机噪声生成1000个数据点,并画出图像。

%matplotlib inline # need by jupyter notebook
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
 
num_points = 1000
vectors_set = []
for i in range (num_points):
    x1 = np.random.normal (0.0, 0.6)
    y1 = x1*0.5+0.3+np.random.normal(0.0,0.3)
    vectors_set.append([x1,y1])
x_data = [v[0] for v in vectors_set]
y_data = [v[1] for v in vectors_set]
# display
plt.scatter (x_data,y_data, c='r')
plt.show

  

 

 

 

 

 

posted @ 2021-01-23 17:32  嘻嘻哒丸子  阅读(44)  评论(0编辑  收藏  举报