{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"import sys\n",
"sys.path.append('/Users/kaonpark/workspace/github.com/likejazz/kaon-learn')\n",
"import kaonlearn\n",
"from kaonlearn.plots import plot_decision_regions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Numbers can encode categoricals"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"
\n",
" \n",
" \n",
" | \n",
" Categorical Feature | \n",
" Integer Feature | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" socks | \n",
" 0 | \n",
"
\n",
" \n",
" 1 | \n",
" fox | \n",
" 1 | \n",
"
\n",
" \n",
" 2 | \n",
" socks | \n",
" 2 | \n",
"
\n",
" \n",
" 3 | \n",
" box | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Categorical Feature Integer Feature\n",
"0 socks 0\n",
"1 fox 1\n",
"2 socks 2\n",
"3 box 1"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# create a dataframe with an integer feature and a categorical string feature\n",
"demo_df = pd.DataFrame({'Integer Feature': [0, 1, 2, 1],\n",
" 'Categorical Feature': ['socks', 'fox', 'socks', 'box']})\n",
"demo_df.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Integer Feature | \n",
" Categorical Feature_box | \n",
" Categorical Feature_fox | \n",
" Categorical Feature_socks | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" 0 | \n",
" 0 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 0 | \n",
"
\n",
" \n",
" 2 | \n",
" 2 | \n",
" 0 | \n",
" 0 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" 1 | \n",
" 1 | \n",
" 0 | \n",
" 0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Integer Feature Categorical Feature_box Categorical Feature_fox \\\n",
"0 0 0 0 \n",
"1 1 0 1 \n",
"2 2 0 0 \n",
"3 1 1 0 \n",
"\n",
" Categorical Feature_socks \n",
"0 1 \n",
"1 0 \n",
"2 1 \n",
"3 0 "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.get_dummies(demo_df)"
]
}
],
"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.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}