{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Categorical FeatureInteger Feature
0socks0
1fox1
2socks2
3box1
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Integer FeatureCategorical Feature_boxCategorical Feature_foxCategorical Feature_socks
00001
11010
22001
31100
\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 }