I am trying to use linear classifier to predict, the constructing and training of the estimator is listed here:
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)
got the error:
AttributeError: module 'tensorflow_estimator.python.estimator.api._v1.estimator' has no attribute 'inpus'
my tensorflow version is 2.4.1
can you please help me to resolve this problem? THX!
update: I have already corrected the typo error, and the error has been fixed, but I got one warning listed here:
The name tf.estimator.inputs.numpy_input_fn is deprecated. Please use tf.compat.v1.estimator.inputs.numpy_input_fn instead.
after I used the suggested function, I got the same wanring listed here:
The name tf.estimator.inputs.numpy_input_fn is deprecated. Please use tf.compat.v1.estimator.inputs.numpy_input_fn instead
It really confused me, can you please help to fix it? THX!
I uploaded my complete code in google drive, this is the link here: https://drive.google.com/file/d/1R6bRcv8Afjx4cPLBZaBpuCcDg71fNN3Y/view?usp=sharing
Your issue can be resolved if you can change
tf.estimator.inpus.numpy_input_fn
totf.estimator.inputs.numpy_input_fn
. It's typo error.You can ignore deprecated warnings.