tensorflow - 如何使用训练有素的估计器在张量流中进行预测
问题描述
我试图使用训练有素的估计器对一些测试数据进行预测,但我的预测结果不好,你能检查一下我的代码吗?许多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))
解决方案
推荐阅读
- javascript - 在 keyup 上添加 2 个输入值以在第 3 个输入框中得到答案
- shell - 如何跳过 ash/dash shell 函数中的第一个参数?
- java - Jooq 替换功能
- shell - ElasticSearch 解析关于“压缩器检测”的错误 POSTing to /_bulk
- android - android constraintLayout ellipsize 文本开始不同的偏移量
- sql-server - 新权限添加到列表。通过触发器更新所有用户以获得新权限
- arrays - 如何在 VbScript 中查找某个单词最后一次作为元素出现在数组中的时间
- php - 通过 PHP / Soap / WSDL 发送带有证书的 XML
- go - 是否可以在 GO 中找到 Windows 上加载的 DLL 的路径?
- asp.net-core - Identity Server 4 身份验证太慢