import numpy as np
import matplotlib.pyplot as plt
import tensorflow.compat.v1 as tf
# tf.enable_eager_execution() # 在TensorFlow1.X版本中启用Eager Execution模式
tf.disable_eager_execution() # 在TensorFlow2.X版本关闭Eager Execution
tf.__version__
1、生成x_data,值为[0, 100]之间500个等差数列数据集合作为样本特征,根据目标线性方程y=3*x+2,生成相应的标签集合y_data
x_data = np.linspace(0, 100, 500)
y_data = 3* x_data + 2 + np.random.randn(500) * 0.5
2、画出随机生成数据的散点图和想要通过学习得到的目标线性函数y=3*x+2
x_data = np.linspace(0, 100, 500)
y_data = 3 * x_data + 2 + np.random.randn(500) * 0.5
plt.figure(figsize=[10, 5])
plt.plot(x_data, y_data, 'r.', markersize=3)
plt.plot(x_data, 3 * x_data + 2, 'b-')
plt.legend(['y_data', 'y=3*x+2'])
3