tensorflow预制估算器:损失正在增加

时间:2019-09-24 11:05:51

标签: tensorflow-estimator

我的损失不断增加

我在做什么错了

import tensorflow as tf
import numpy as np
import pandas as pd

tf.version.VERSION


######################################################################################
##Create TEST DATA
######################################################################################

def testdata_create_csv(from_number=0,number_of_rows=1000,filename='houseprices.csv'):
    f = open(filename,'w')
    for i in np.arange(0,number_of_rows):
        f.writelines(str(i) + ',' + str(i) + ',' + str(np.square(i) + i) + '\n')
    f.close()


testdata_create_csv(from_number=11111,number_of_rows=10000,filename='houseprices.csv')
testdata_create_csv(from_number=0,number_of_rows=300,filename='evaluate.csv')

#######################################################################################

我用基本数据创建了csv文件。

##Import the data in dataframes
df_train = pd.read_csv('houseprices.csv',names=['a','b','target'])
df_evaluate = pd.read_csv('evaluate.csv',names=['a','b','target'])

我想对所有列定义使用Pandas数据框

##create Feature columns
feature_columns = []
feature_columns.append(tf.feature_column.numeric_column(key='a',dtype=tf.int64))
feature_columns.append(tf.feature_column.numeric_column(key='b',dtype=tf.int64))

试图使用from_tensor_slices创建数据集

##Define Input function
def input_fn(df,shuffle=False,batch_size=10):
    features = df.copy()
    labels = features.pop('target')
    dataset = tf.data.Dataset.from_tensor_slices((dict(features), labels))
    if shuffle:
        # Shuffle, repeat, and batch the examples.
        dataset = dataset.shuffle(10000).repeat().batch(batch_size)
    dataset = dataset.batch(batch_size)
    return dataset

仅以功能列定义模型,而没有更多信息

##Create Model
model = tf.estimator.LinearRegressor(feature_columns=feature_columns)

##Train Model
model.train(input_fn=lambda:input_fn(df_train))

##Evaluate Model
model.evaluate(input_fn=lambda:input_fn(df_evaluate))

0 个答案:

没有答案