简体   繁体   中英

Tensorflow: How to train a Linear Regression?

I'm learning to train a Linear Regression model via TensorFlow. It's quite a simple formula:

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. So, Loss is quite high.

Here is my code.

在此处输入图片说明

QUESTION

Why is " b " being trained a wrong way?

Shall I do something with the optimizer?

On line 16 , you are adding gaussian noise with a standard deviation of 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).

Also, 20k iterations is more than enough (in this problem) for training.

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. 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其估计受noise的初始“骰子滚动”(标准偏差为N )的影响远大于b_true的实际值(后者小得多)比N )。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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