Comments (6)
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.
Me too
from artificial-intelligence-with-python.
/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.
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.
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.
@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)
- code error
- Chapter 3, Building a Decision Tree Classifier HOT 1
- Ch 4: Building a classifier based on Gaussian Mixture Models HOT 2
- chapter04 stocks.py matplotlib.finance removed
- fit() missing 1 required positional argument: 'y'
- data_multivar_nb.txt file for Naïve Bayes classifier
- G
- true labels and pred labels
- OS error HOT 1
- Incorrect working grid_search. HOT 2
- error with naive_bayes.py HOT 1
- Chapter 3. Random Forest Classifier.
- Running this prime.py script
- python3 not found
- missing preprocessing.py HOT 1
- Chapter 6 - Virginia is not in Costal States HOT 1
- No module named 'utilities' HOT 3
- from utilities import visualize_classifier HOT 8
- Artificial-Intelligence-with-Python/Chapter 03/code/traffic_prediction.py HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from artificial-intelligence-with-python.