Created
January 13, 2019 22:13
-
-
Save pascalwhoop/60ea066e46b39cbbd779fc0ef13fa120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import helpers\n", | |
"from sklearn import preprocessing\n", | |
"X_test, y_test = helpers.get_data(subset=\"test\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array(['Cambodia', 'Canada', 'China', 'Columbia', 'Cuba',\n", | |
" 'Dominican-Republic', 'Ecuador', 'El-Salvador', 'England',\n", | |
" 'France', 'Germany', 'Greece', 'Guatemala', 'Haiti', 'Honduras',\n", | |
" 'Hong', 'Hungary', 'India', 'Iran', 'Ireland', 'Italy', 'Jamaica',\n", | |
" 'Japan', 'Laos', 'Mexico', 'Nicaragua',\n", | |
" 'Outlying-US(Guam-USVI-etc)', 'Peru', 'Philippines', 'Poland',\n", | |
" 'Portugal', 'Puerto-Rico', 'Scotland', 'South', 'Taiwan',\n", | |
" 'Thailand', 'Trinadad&Tobago', 'United-States', 'Vietnam',\n", | |
" 'Yugoslavia', 'nan'], dtype=object)" | |
] | |
}, | |
"execution_count": 19, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"le = preprocessing.LabelEncoder()\n", | |
"le.fit(X_test['native-country'].astype(str))\n", | |
"countries = le.classes_\n", | |
"countries" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n", | |
" 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,\n", | |
" 34, 35, 36, 37, 38, 39, 40])" | |
] | |
}, | |
"execution_count": 18, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"le.transform(countries)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment