简体   繁体   English

Tensorflow:如何训练线性回归?

[英]Tensorflow: How to train a Linear Regression?

I'm learning to train a Linear Regression model via TensorFlow. 我正在学习通过TensorFlow训练线性回归模型。 It's quite a simple formula: 这是一个很简单的公式:

y = W * x + b y = W * x + b

I have generated a sample data: 我生成了一个样本数据:

在此处输入图片说明

After the model training I can see in Tensorboard that " W " is correct when " b " goes a completely wrong way. 经过模型训练后,我可以在Tensorboard中看到,当“ b ”完全错误时,“ W ”是正确的。 So, Loss is quite high. 因此,损失很高。

Here is my code. 是我的代码。

在此处输入图片说明

QUESTION

Why is " b " being trained a wrong way? 为什么“ b ”训练有误?

Shall I do something with the optimizer? 我可以对优化器做些什么吗?

On line 16 , you are adding gaussian noise with a standard deviation of 300!! 在第16行上 ,您要添加标准偏差为300的高斯噪声!

noise = np.random.normal(scale=n, size=(N, 1))

Try using: 尝试使用:

noise = np.random.normal(size=(N, 1))

That's using mean=0 and std=1 (standard Gaussian noise). 这使用的是均值= 0和std = 1(标准高斯噪声)。

Also, 20k iterations is more than enough (in this problem) for training. 同样,对于该训练而言,20k次迭代已足够(在此问题中)。

For a more comprehensive explanation of what is happening, look at your plot. 有关发生的情况的更全面的说明,请查看您的情节。 Given an x value, the possible values for y have thousands of units of difference. 给定x值, y的可能值具有数千个单位的差。 That means that there are a lot of lines that explain your data. 这意味着有很多行可以解释您的数据。 Hence a lot of values for B are possible, but no matter which one you choose (even the true b value) all of them are going to have a big loss. 因此,B可以有​​很多值,但是无论您选择哪一个(甚至是真正的b值),所有这些都会损失很大。

优化工作正常,但问题出在参数b其估计受noise的初始“骰子滚动”(标准偏差为N )的影响远大于b_true的实际值(后者小得多)比N )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM