通过生成人工数据集合,基于TensorFlow实现y=3*x+2线性回归

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值