我试图在没有太多外部帮助的情况下对线性回归进行编程,我已经成功地完成了这项工作,因为我的MSE通常返回一个较小的数字,并且输出的最佳拟合线看起来是正确的。我只是对下面最后一行代码有个问题。优化器是否也会改变偏差,如果是,是否会根据学习速率来改变?
#tf graph input, the 9 training values
X = tf.placeholder("float")
Y = tf.placeholder("float")
random = random.uniform(0,20)
#weights and biases
W = tf.Variable((random), name = "Weight")
b = tf.Variable((random), name = "Bias")
#linear model multiply x by weights and biases to get a y
pred = tf.add(tf.multiply(X, W), b)
#cost function to reduce the error. MSE
cost = tf.reduce_sum(tf.pow(pred-Y, 2))/(2*n_samples)
#minimize cost taking steps of 0.01 down the parabola
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)