我尝试使用线性分类器进行预测,估计量的构造和训练如下所示:
model = tf.estimator.LinearClassifier(
n_classes = 2,
model_dir = "ongoing",
feature_columns = categorical_features + continuous_features
(
FEATURES = ['Age', 'Gender', 'ICD9Code']
LABEL = 'Condition'
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
model.train(
input_fn = get_input_fn(csv_data, num_epochs = None, n_batch = 10461, shuffle = False
),
steps = 1000
)
predict_data = pd.read_csv('feature_condition.csv', usecols = ['PatientGuid', 'Age', 'Gender', 'ICD9Code'], nrows = 5)
predict_input_fn = tf.estimator.inpus.numpy_input_fn(
x = {"x": predict_data},
y = None,
batch_size = 5,
shuffle = False,
num_threads = 5
)
predict_results = model.predict(predict_input_fn)
print(predict_results)
获取错误信息:
AttributeError: module 'tensorflow_estimator.python.estimator.api._v1.estimator' has no attribute 'inpus'
我的tensorflow版本是2.4.1
你能帮我解决这个问题吗?谢谢
更新:我已经更正了输入错误,错误已经修复,但我得到了一个警告:
The name tf.estimator.inputs.numpy_input_fn is deprecated. Please use tf.compat.v1.estimator.inputs.numpy_input_fn instead.
使用建议的函数后,我得到了这里列出的相同的Warning:
The name tf.estimator.inputs.numpy_input_fn is deprecated. Please use tf.compat.v1.estimator.inputs.numpy_input_fn instead
我真的很困惑,你能帮我修一下吗?谢谢
我在google drive中上传了我的完整代码,这里是链接: https://drive.google.com/file/d/1R6bRcv8Afjx4cPLBZaBpuCcDg71fNN3Y/view?usp=sharing
如果您可以将
tf.estimator.inpus.numpy_input_fn
更改为tf.estimator.inputs.numpy_input_fn
,您的问题可以得到解决。这是打字错误您可以忽略不推荐使用的警告
相关问题 更多 >
编程相关推荐