{ "metadata": { "name": "", "signature": "sha256:fec8df09b2bb6b6c1330a76680df5b086d6f65f8e18f2243640b8b0b357b70e6" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "%%file util.py\n", "from math import ceil\n", "from matplotlib import pyplot as pl\n", "\n", "MODEL_NAME = 'model'\n", "\n", "NUM_COLS = 5\n", "PLOT_LEN = 3\n", "FONT_SIZE = 25\n", "CMAP = 'gray_r'\n", "\n", "def show_digits_plots(digitos, ini, fim):\n", " \n", " num_digits = fim - ini + 1\n", " num_rows = int(ceil((1.*num_digits)/NUM_COLS))\n", " \n", " fig, axes = pl.subplots(num_rows, NUM_COLS, figsize=(PLOT_LEN*NUM_COLS, PLOT_LEN*num_rows))\n", "\n", " for ax, i in zip(axes.ravel(), xrange(ini, fim+1)):\n", "\n", " ax.plot(xrange(len(digitos.data[i])), digitos.data[i])\n", " ax.set_title(\"%d\" % digitos.target[i])\n", "\n", "def show_digits(digitos, ini, fim):\n", " \n", " num_digits = fim - ini + 1\n", " num_rows = int(ceil((1.*num_digits)/NUM_COLS))\n", " \n", " fig, axes = pl.subplots(num_rows, NUM_COLS, figsize=(PLOT_LEN*NUM_COLS, PLOT_LEN*num_rows))\n", " \n", " for ax in axes.ravel():\n", " \n", " ax.axis('off')\n", " \n", " for ax, i in zip(axes.ravel(), xrange(ini, fim+1)):\n", " \n", " # no lugar de data[i].reshape((8,8)) pode-se utilizar images[i]\n", " ax.imshow(digitos.data[i].reshape((8, 8)), cmap=CMAP, interpolation='nearest')\n", " ax.set_title('%d' % digitos.target[i], fontsize=FONT_SIZE)\n", " \n", "def show_confusion_matrix(cm):\n", " \n", " fig = pl.figure(figsize=(5,5))\n", " ax = fig.add_subplot(1,1,1)\n", " im = ax.matshow(cm)\n", " ax.set_xlabel('predito')\n", " ax.set_ylabel('real')\n", " r_10 = range(10)\n", " ax.set_xticks(r_10)\n", " ax.set_xticklabels(r_10)\n", " ax.set_yticklabels(r_10)\n", " ax.set_yticks(r_10)\n", " _ = fig.colorbar(im)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Overwriting util.py\n" ] } ], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }