Print predict ValueError: Expected 2D array, got 1D array instead

后端 未结 1 1965
你的背包
你的背包 2021-01-29 15:16

The error shows in my last two codes.

ValueError: Expected 2D array, got 1D array instead: array=[0 1].


1条回答
  •  时光说笑
    2021-01-29 15:53

    The error message is self-explanatory. Your library expects the input to be a 2D matrix, with one pattern per row. So, if you are doing regression with just one input, before passing it to the regressor, do

    my_data = my_data.reshape(-1, 1)
    

    to make a 2X1 shaped matrix

    On the other hand (unlikely), if you have a single vector [0, 1]

    my_data = my_data.reshape(1, -1) 
    

    to make a 1X2 matrix

    0 讨论(0)
提交回复
热议问题