[solved] error: valueerror: expected 2D array, got scalar array instead

Error code:

new_x = 84610
pre_y = model.predict(new_x)
print(pre_y)

Error result:

ValueError: Expected 2D array, got scalar array instead:
array=84610.
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

Solution:

Reshape data using array
Reshape data using array
Reshape data using array If the data has a single function or array, resize the shape (-1, 1). If the data contains a single example, resize the shape (1, -1).
Solution:
add

new_x = np.array(new_x).reshape(1, -1)

Modified code:

new_x = 84610
new_x = np.array(new_x).reshape(1, -1)
pre_y = model.predict(new_x)
print(pre_y)

Reproduced in: https://www.cnblogs.com/hankleo/p/11310272.html

Read More: