Tensorflow - Core Learning Algorithms: Building the Model

Tell us what’s happening:
I wanna run the Machine Learning with Python from the Tensorflow while doing “Core Learning Algorithms: Building the Model” from freeCodeCamp there is an error. Below, on the line “for pred_dict in predictions:” the error is happened with the red underline.

Your code so far
def input_fn(features, batch_size=256):
# Convert the inputs to a Dataset without labels.
return tf.data.Dataset.from_tensor_slices(dict(features)).batch(batch_size)

features = [‘SepalLength’, ‘SepalWidth’, ‘PetalLength’, ‘PetalWidth’]
predict = {}

print(“Please type numeric values as prompted.”)
for feature in features:
valid = True
while valid:
val = input(feature + ": ")
if not val.isdigit(): valid = False

predict[feature] = [float(val)]

predictions = classifier.predict(input_fn=lambda: input_fn(predict))
for pred_dict in predictions:
print(pred_dict)
class_id = pred_dict[‘class_ids’][0]
probability = pred_dict[‘probabilities’][class_id]

print('Prediction is "{}" ({:.1f}%)'.format(
    SPECIES[class_id], 100 * probability)) 

Your browser information:
Here is the feedback from the error:
ValueError Traceback (most recent call last)
in <cell line: 18>()
16
17 predictions = classifier.predict(input_fn=lambda: input_fn(predict))
—> 18 for pred_dict in predictions:
19 print(pred_dict)
20 class_id = pred_dict[‘class_ids’][0]

6 frames
/usr/local/lib/python3.10/dist-packages/tensorflow_estimator/python/estimator/canned/dnn.py in tf__call(self, features, mode)
11 is_training = ag__.ld(mode) == ag__.ld(ModeKeys).TRAIN
12 try:
—> 13 net = ag__.converted_call(ag__.ld(self).input_layer, (ag_.ld(features),), dict(training=ag__.ld(is_training)), fscope)
14 except TypeError:
15 net = ag__.converted_call(ag__.ld(self).input_layer, (ag_.ld(features),), None, fscope)

ValueError: in user code:

File "/usr/local/lib/python3.10/dist-packages/tensorflow_estimator/python/estimator/canned/dnn.py", line 346, in call  *
    net = self._input_layer(features, training=is_training)
File "/usr/local/lib/python3.10/dist-packages/keras/src/engine/base_layer_v1.py", line 838, in __call__  **
    outputs = call_fn(cast_inputs, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/keras/src/feature_column/dense_features.py", line 184, in call  **
    tensor = column.get_dense_tensor(

ValueError: Feature Sepalength is not in features dictionary.

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36

Challenge: Tensorflow - Core Learning Algorithms: Building the Model

Link to the challenge:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.