tensorflow估计器LinearRegressor:为什么我的损失这么大

时间:2018-12-17 12:05:25

标签: tensorflow tensorflow-estimator

我使用来自tensorflow估计器库(tf.estimator.LinearRegressor)的LinearRegressor进行我的tensorflow模型训练,评估和预测。但是,评估始终显示出非常大的损失值。因此,这些预测是完全不正确的。

这是我定义火车,评估,预测输入函数和LinearRegressor的方式:

def train_input_fn(x, y):
    training_input_fn = tf.estimator.inputs.pandas_input_fn(
        x = x,
        y = y,
        batch_size = 32,
        shuffle = True,
        num_epochs = None
    )
    return training_input_fn

def eval_input_fn(x, y):
    eval_input_fn = tf.estimator.inputs.pandas_input_fn(
        x = x,
        y = y,
        batch_size = 32,
        shuffle = False,
        num_epochs = 1
    )
    return eval_input_fn

def predict_input_fn(x):
    predict_input_fn = tf.estimator.inputs.pandas_input_fn(
        x = x,
        shuffle = False,
        num_epochs = 1 
    )
    return predict_input_fn

def get_linear_regressor():
    properties = load_data()
    del properties['_id']
    X_train, X_test, y_train, y_test = split_data(properties)
    linear_regressor = tf.estimator.LinearRegressor(feature_columns=build_features(),
                                                    model_dir = "linear_regressor")
    linear_regressor.train(input_fn = train_input_fn(X_train, y_train), steps=5000)

    loss = linear_regressor.evaluate(input_fn = eval_input_fn(X_test, y_test))
    print("Loss is: " + str(loss))
    return linear_regressor

结果:

  

损失为:{'average_loss':417497550000.0,'label / mean':751504.7,   '损失':13186813000000.0,'预测/平均值':331845.62,'global_step':   145000}

我有6472个数据点,以8:2的比例进行了训练和评估。

我做错了什么?如何提高预测的准确性?

0 个答案:

没有答案
相关问题