1

线性方程:

a = linear_regressor.get_variable_value('linear/weight/weight')[0][0]
b = linear_regressor.get_variable_value('linear/bias_weight')[0]

def predict_custom(x):
  return a * x + b

和结果比较:

linear_regressor.predict(input_fn=input_const(30, WEIGHT_COL))
# array([ 84.63061523], dtype=float32)
predict_custom(30)
# 75.9105224609375

通过“预测”方法获得的结果的可视化:

在此处输入图像描述

通过“predict_custom”方法获得的结果的可视化:

在此处输入图像描述

两者相似,但仍然不同。为什么会这样?如果我的理解是正确的,“LinearRegressor”的“预测”方法应该使用与“custom_predict”方法相同的权重。

4

0 回答 0