{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Let's look at the classic iris dataset.\n", "\n", "First we need tell ipython that we want our plots to show up within the notebook, rather than within a separate window. We can do this with a magic command, which is the name in ipython for a command that starts with a %." ] }, { "cell_type": "code", "collapsed": false, "input": [ "%matplotlib inline" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we have our import statements. We'll need matplotlib.pyplot for visualization and pandas to use data frames." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import matplotlib.pyplot as plt\n", "import pandas as pd" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we need to import the iris dataset. In our .py script, this was eight lines of code. With pandas, it's just three!" ] }, { "cell_type": "code", "collapsed": false, "input": [ "url = \"http://mlr.cs.umass.edu/ml/machine-learning-databases/iris/iris.data\"\n", "\n", "# Define our headers since the url doesn't contain explicit headers\n", "# I found these headers from looking at the documentation at\n", "# http://mlr.cs.umass.edu/ml/machine-learning-databases/iris/iris.names\n", "headers = ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width', 'Class'\n", "\t]\n", "iris = pd.read_csv(url, header=None, names=headers)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's see what the data looks like." ] }, { "cell_type": "code", "collapsed": false, "input": [ "iris[:3]" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", " | Sepal Length | \n", "Sepal Width | \n", "Petal Length | \n", "Petal Width | \n", "Class | \n", "
---|---|---|---|---|---|
0 | \n", "5.1 | \n", "3.5 | \n", "1.4 | \n", "0.2 | \n", "Iris-setosa | \n", "
1 | \n", "4.9 | \n", "3.0 | \n", "1.4 | \n", "0.2 | \n", "Iris-setosa | \n", "
2 | \n", "4.7 | \n", "3.2 | \n", "1.3 | \n", "0.2 | \n", "Iris-setosa | \n", "
3 rows \u00d7 5 columns
\n", "