Skip to content
Advertisement

Python : y should be a 1d array, got an array of shape {} instead. format(shape)

JavaScript

The above is my code which I tried in Google Colab. But here it shows one error :

JavaScript

This is error is shown in the line

JavaScript

Please help me to solve this error. I am a beginner so answer the question with elaboration

Advertisement

Answer

Your problem is that the outputs of train_test_split are ordered differently than you think.

train_test_split returns the split of the first argument first, then the split of the second argument. So instead you should use it like

JavaScript

You can find more information and a few examples in the documentation.

You can resolve issues like that by inspecting the shapes of the values of your variables. Either use a debugger or print their shapes:

JavaScript

Now you can see why the error is raised and you can see where things go wrong. Then you can lookup the documentation of the last command that produced unexpected outputs.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement