如何使用训练有素的估计器在张量流中进行预测

问题描述

我试图使用训练有素的估计器对一些测试数据进行预测,但我的预测结果不好,您能检查一下我的代码吗?许多 THX!

这是下面的代码:

//create the estimator
model = tf.estimator.LinearClassifier(
  n_classes = 2,model_dir = "ongoing",feature_columns = categorical_features + continuous_features
)

FEATURES = ['Age','Gender','ICD9Code']
LABEL = 'Condition'

//create the input function
def get_input_fn(data_set,num_epochs,n_batch,shuffle):
    input = tf.compat.v1.estimator.inputs.pandas_input_fn(
       x = pd.DataFrame({k: data_set[k].values for k in FEATURES}),y = pd.Series(data_set[LABEL].values),batch_size = n_batch,num_epochs = num_epochs,shuffle = shuffle
     )
    return input

//train the estimator
model.train(
  input_fn = get_input_fn(csv_data,num_epochs = None,n_batch = 10461,shuffle = False
  ),steps = 1000
)
//create the prediction input function
predict_input_fn = tf.compat.v1.estimator.inputs.numpy_input_fn(
                          x = {k: df[k].values for k in FEATURES},//df is the test data set
                          y = None,batch_size = 1,num_epochs = 1,shuffle = False,num_threads = 1
                       )
 predict_results = model.predict(predict_input_fn)
 print(row_pre,next(predict_results))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)