Giter Club home page Giter Club logo

Comments (6)

SuuSoJeat avatar SuuSoJeat commented on August 14, 2024 7

I found the solution -- not sure whether it's best practice.
Change the following lines of code:
input_data_encoded[i] = int(label_encoder[count].transform(input_data[i]))
to
input_data_encoded[i] = int(label_encoder[count].transform([input_data[i]]))
and
input_data_encoded = np.array(input_data_encoded)
to
input_data_encoded = np.array(input_data_encoded).reshape(1, -1)

from artificial-intelligence-with-python.

SuuSoJeat avatar SuuSoJeat commented on August 14, 2024

Me too

from artificial-intelligence-with-python.

SuuSoJeat avatar SuuSoJeat commented on August 14, 2024

/home/suusojeat/PycharmProjects/ArtificialIntelligencePrateekJoshi/venv/bin/python /home/suusojeat/PycharmProjects/ArtificialIntelligencePrateekJoshi/income_classifier.py
/home/suusojeat/PycharmProjects/ArtificialIntelligencePrateekJoshi/venv/lib/python3.6/site-packages/sklearn/cross_validation.py:41: 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)
F1 score: 71.35%
Traceback (most recent call last):
File "/home/suusojeat/PycharmProjects/ArtificialIntelligencePrateekJoshi/income_classifier.py", line 164, in
input_data_encoded[i] = int(label_encoder[count].transform(input_data[i]))
File "/home/suusojeat/PycharmProjects/ArtificialIntelligencePrateekJoshi/venv/lib/python3.6/site-packages/sklearn/preprocessing/label.py", line 128, in transform
y = column_or_1d(y, warn=True)
File "/home/suusojeat/PycharmProjects/ArtificialIntelligencePrateekJoshi/venv/lib/python3.6/site-packages/sklearn/utils/validation.py", line 614, in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape ()

Process finished with exit code 1

from artificial-intelligence-with-python.

satiayuga avatar satiayuga commented on August 14, 2024

Hi, I did your solution, but now i have this error:
input_data_encoded[i] = label_encoder[count].transform([input_data[i]])
File "C:\Python35\lib\site-packages\sklearn\preprocessing\label.py", line 133, in transform
raise ValueError("y contains new labels: %s" % str(diff))
ValueError: y contains new labels: ['Tuesday']

You can help me please?

from artificial-intelligence-with-python.

kylek29 avatar kylek29 commented on August 14, 2024

@SuuSoJeat

That fixed it for me. Maybe do a commit of the fix? See if they'll roll it in.

@satiayuga
You'd need to post more of your script so we can see where 'Tuesday' is being introduced. The income_data.txt file doesn't contain it, so it's not being created as a label when it builds the model. When you do the Predict Output part (get a prediction for a given person), you have to use labels it already knows.

For example, if I change:
input_data = ['37', 'Private', '215646', 'HS-grad', '9', 'Never-married', 'Handlers-cleaners', 'Not-in-family', 'White', 'Male', '0', '0', '40', 'United-States']
to
input_data = ['37', 'Private', '215646', 'HS-grad', '9', 'Never-married', 'Handlers-cleaners', 'Not-in-famil', 'White', 'Male', '0', '0', '40', 'United-States']
^^ I changed "Not-in-family" to "Not-in-famil"

I get that same error, except stating my "Not-in-famil" label doesn't exist. The error is telling us that the model doesn't know what that label is and thus can't map it to a value to make a prediction.

from artificial-intelligence-with-python.

argctl avatar argctl commented on August 14, 2024

@SuuSoJeat
You can also fix the second issue with the same method:
predicted_class = classifier.predict([input_data_encoded])

from artificial-intelligence-with-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.