Error while running C1W1 assignment on a windows laptop

I tried to run the C1W1 assignment (predicting house model) on a windows 10 (x86_64) laptop with this code block

new_x = 7.0
prediction = model.predict([x=new_x])

I got this error
“ValueError: Unrecognized data type: x=7.0 (of type <class ‘float’>)”

I read somewhere (I lost the link to the answer in forum) that I have to assign this as a numpy array

new_x = np.array([7.0])
prediction = model.predict(x=new_x)

Like this. Since, I will be working on this laptop, I am trying to understand why this is happening and what can i do so that my tensorflow conda environment behaves in a similar way like the course notebook.
Thanks for your help,

I would suggest to try and find the Tensorflow version used in the Lab and also the versions of the other packages too (Numpy included), as well as python release used. Next to study those helper files on the Lab (File-> Open) if there are any!

1 Like


Can you share the screenshot of the error you are mentioning as the part of code you share is not a part of grade cell and it was already given in the assignment.

Because this error could be from the grade cell where you define your variable xs and ys, which should a data type float, I hope you have selected the same while defining the variables.


Hi Deepti,
Here is the model function I used

def house_model():
    xs = np.array([1.0,  2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], dtype=float)
    ys = np.array([1.0,  1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5], dtype=float)

    model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
    model.compile(optimizer='sgd', loss="mean_squared_error"), ys, epochs=500)
    return model

and the full error

ValueError Traceback (most recent call last) Cell In[9], [line 2](vscode-notebook-cell:?execution_count=9&line=2) [1](vscode-notebook-cell:?execution_count=9&line=1) new_x = 7.0 ----> [2](vscode-notebook-cell:?execution_count=9&line=2) prediction = model.predict([new_x])[0] [3](vscode-notebook-cell:?execution_count=9&line=3) print(prediction) File c:\Users\abhik\miniconda3\envs\aicore\lib\site-packages\keras\src\utils\, in filter_traceback.<locals>.error_handler(*args, **kwargs) [119](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/utils/ filtered_tb = _process_traceback_frames(e.__traceback__) [120](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/utils/ # To get the full stack trace, call: [121](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/utils/ # `keras.config.disable_traceback_filtering()` --> [122](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/utils/ raise e.with_traceback(filtered_tb) from None [123](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/utils/ finally: [124](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/utils/ del filtered_tb File c:\Users\abhik\miniconda3\envs\aicore\lib\site-packages\keras\src\trainers\data_adapters\, in get_data_adapter(x, y, sample_weight, batch_size, steps_per_epoch, shuffle, class_weight) [105](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/trainers/data_adapters/ return GeneratorDataAdapter(x) [106](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/trainers/data_adapters/ # TODO: should we warn or not? [107](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/trainers/data_adapters/ # warnings.warn( [108](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/trainers/data_adapters/ # "`shuffle=True` was passed, but will be ignored since the " (...) [111](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/trainers/data_adapters/ # ) [112](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/trainers/data_adapters/ else: --> [113](file:///C:/Users/abhik/miniconda3/envs/aicore/lib/site-packages/keras/src/trainers/data_adapters/ raise ValueError(f"Unrecognized data type: x={x} (of type {type(x)})") ValueError: Unrecognized data type: x=[7.0] (of type <class 'list'>)

Thanks for looking into this

First of all this looks like course assignment, you didn’t confirm this?

You surely did add dtype to your xs, but didn’t apply the same to your new_x, causing this error…

Note if the above code is from a course assignment where your assignment is graded, then kindly remove your codes from your post.

1 Like