{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Add the facets overview python code to the python path\n", "import sys\n", "sys.path.append('./python')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Load UCI census train and test data into dataframes.\n", "import pandas as pd\n", "features = [\"Age\", \"Workclass\", \"fnlwgt\", \"Education\", \"Education-Num\", \"Martial Status\",\n", " \"Occupation\", \"Relationship\", \"Race\", \"Sex\", \"Capital Gain\", \"Capital Loss\",\n", " \"Hours per week\", \"Country\", \"Target\"]\n", "train_data = pd.read_csv(\n", " \"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data\",\n", " names=features,\n", " sep=r'\\s*,\\s*',\n", " engine='python',\n", " na_values=\"?\")\n", "test_data = pd.read_csv(\n", " \"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.test\",\n", " names=features,\n", " sep=r'\\s*,\\s*',\n", " skiprows=[0],\n", " engine='python',\n", " na_values=\"?\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Calculate the feature statistics proto from the datasets and stringify it for use in facets overview\n", "from generic_feature_statistics_generator import GenericFeatureStatisticsGenerator\n", "import base64\n", "\n", "gfsg = GenericFeatureStatisticsGenerator()\n", "proto = gfsg.ProtoFromDataFrames([{'name': 'train', 'table': train_data},\n", " {'name': 'test', 'table': test_data}])\n", "protostr = base64.b64encode(proto.SerializeToString()).decode(\"utf-8\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Display the facets overview visualization for this data\n", "from IPython.core.display import display, HTML\n", "\n", "HTML_TEMPLATE = \"\"\"\n", " \n", " \"\"\"\n", "html = HTML_TEMPLATE.format(protostr=protostr)\n", "display(HTML(html))" ] } ], "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.4.3" } }, "nbformat": 4, "nbformat_minor": 2 }