Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter02/car.py returns bad input shape #1

Open
mikayla-grace opened this issue Dec 7, 2016 · 1 comment
Open

Chapter02/car.py returns bad input shape #1

mikayla-grace opened this issue Dec 7, 2016 · 1 comment

Comments

@mikayla-grace
Copy link

mikayla-grace commented Dec 7, 2016

Chapter02/car.py returns bad input shape with scikit-learn 0.18-2. How to fix?

-> python car.py
/usr/lib64/python2.7/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
  "This module will be removed in 0.20.", DeprecationWarning)
Accuracy of the classifier: 78.19%
Traceback (most recent call last):
  File "car.py", line 45, in <module>
    input_data_encoded[i] = int(label_encoder[i].transform(input_data[i]))
  File "/usr/lib64/python2.7/site-packages/sklearn/preprocessing/label.py", line 143, in transform
    y = column_or_1d(y, warn=True)
  File "/usr/lib64/python2.7/site-packages/sklearn/utils/validation.py", line 562, in column_or_1d
    raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape ()
@kietikul
Copy link

I've got the same problem. Here is the solution that I figured out.
Replace the code in line 45 by the following line:

  input_data_encoded[i] = int(label_encoder[i].transform([input_data[i]]))

The function transform() takes parameter as a list of values. Even you have a single value, you still have to convert into a list of a single value, i.e., [input_data[i]].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants