{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Cross Validation and Hyperparameter Optimization\n", "\n", "In this notebook, we will\n", " \n", " * split the sample data into test and training sets,\n", " \n", " * optimize the `Nbin` hyperparameter,\n", " \n", " * learn to use [Sklearn](http://scikit-learn.org) to cross validate the model.\n", " " ] }, { "cell_type": "code", "collapsed": false, "input": [ "%matplotlib inline\n", "%load_ext autoreload\n", "%autoreload 2\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from pymks import MKSRegressionModel\n", "from pymks import FiPyCHModel" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The autoreload extension is already loaded. To reload it, use:\n", " %reload_ext autoreload\n" ] } ], "prompt_number": 24 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make some actual data (400 samples) with a random seed of 101." ] }, { "cell_type": "code", "collapsed": false, "input": [ "np.random.seed(101)\n", "X = np.random.random((400, 21, 21))\n", "fipymodel = FiPyCHModel()\n", "y = fipymodel.predict(X)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 25 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The FiPy Cahn-Hilliard model has been packaged into the `FiPyCHModel` class within the `fit`, `predict` paradigm." ] }, { "cell_type": "code", "collapsed": false, "input": [ "fipymodel.fit(None, None)" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "NotImplementedError", "evalue": "", "output_type": "pyerr", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNotImplementedError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mfipymodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;32m/home/wd15/git/pymks/pymks/fipyCHModel.pyc\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, X, y)\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 16\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mX\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 17\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 18\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mNotImplementedError\u001b[0m: " ] } ], "prompt_number": 26 }, { "cell_type": "code", "collapsed": false, "input": [ "??fipymodel" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 27 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A sanity check\n", "\n", "Let's fit the data." ] }, { "cell_type": "code", "collapsed": false, "input": [ "model = MKSRegressionModel(Nbin=10)\n", "model.fit(X, y)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 28 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `model` now knows its coefficients" ] }, { "cell_type": "code", "collapsed": false, "input": [ "model.Fcoeff.shape" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 29, "text": [ "(21, 21, 10)" ] } ], "prompt_number": 29 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's check that the fit sort of \"looks right\" with one test sample" ] }, { "cell_type": "code", "collapsed": false, "input": [ "np.random.seed(102)\n", "X_test = np.random.random((1,) + X.shape[1:])\n", "y_test = fipymodel.predict(X_test)\n", "y_pred = model.predict(X_test)\n", "\n", "np.random.seed(2)\n", "index = np.random.randint(len(y_test.flatten()), size=10)\n", "print y_test.flatten()[index]\n", "print y_pred.flatten()[index]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[ 23950253.78282328 13425583.87216846 10370446.72304489\n", " -5082255.45966469 -37232615.87479136 26787885.25872419\n", " 24692312.47186198 27598782.37350243 2548349.44343853\n", " 9095170.78582771]\n", "[ 23924081.38330398 13398981.55267717 10372689.12723125\n", " -5103357.55708055 -37274867.56519653 26809449.81666655\n", " 24722045.53760792 27628866.17868118 2557932.70513815\n", " 9110175.33127277]\n" ] } ], "prompt_number": 30 }, { "cell_type": "markdown", "metadata": {}, "source": [ "and check the \"mean square error\" using Sklearn's `mean_squared_error` function." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from sklearn import metrics\n", "mse = metrics.mean_squared_error\n", "'%1.3e' % np.sqrt(mse(y_test, y_pred))" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 31, "text": [ "'5.984e+04'" ] } ], "prompt_number": 31 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seems okay. How do the coefficients look?" ] }, { "cell_type": "code", "collapsed": false, "input": [ "coeff = np.fft.ifftn(model.Fcoeff, axes=(0, 1)).real\n", "Nroll = coeff.shape[0] / 2\n", "coeff_rolled = np.roll(np.roll(coeff[:,:,0], Nroll, axis=0), Nroll, axis=1)\n", "plt.contourf(coeff_rolled, 249)\n", "plt.colorbar()" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 32, "text": [ "" ] }, { "metadata": {}, "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAWEAAAEDCAYAAADkw7WGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnV2MHNeV3/9NckRREsmeHsq7ieCs2BwGyxhwRHGoZGmI\nGbGHzEIrB47G5uhhHxJAPbCeI5pjIEEoJAAlDPxsa4pAFkgCxMNub4K1nUDsiibiLjdZt3qUTQIl\nJtWTjb2xA6t7mqZEiuLH5KHn1tyuqY9bVbeq7r11fkBhpru+bt2Pf50+deuc0sbGxgYIgiCIXNiR\ndwEIgiCKDIkwQRBEjpAIEwRB5AiJMEEQRI6QCBMEQeTIrrwLQBAEkTeNRgPLy8uoVCo4dOgQzp07\nl9m5SzRFjSAI0zl//jzeeust53Oz2US5XEa320W9Xsfa2hoOHjwI27Zx/Phx7Nu3L7OykTuCIAij\nWVpaQrPZdD53Oh0AQK1WAwCsrq7i4MGDzvosBRggESYIwnDm5+dRrVadz8vLyxgfHwcAVKtVtFot\nAEOXRKVSybx8JMIEQWjN6uoq1tbWnM+2bePmzZu+2w8GgxGx7fV6AIC1tbURsc4KEmGCILTm6NGj\naLVaWFtbg23bAID9+/cH7uP1KOzcuXOh+6UBiTBBENpTr9fx1ltvodvtOr5eP8rlMvr9PgBgfX0d\nExMTWRTRl1ARtiwLlmVhYWHB+a7ZbMK2bViWlWrhCIIgRLBtG9/4xjcAYMQ14cXc3By63a6z7enT\np1MvXxCBImzbNmZmZlCv19HtdmHbNlZXVwGMPlkkCILIC16T6vU6Wq3WiE+40Wig3W7j0qVLAIbu\nC2Cob+VyGc8880z2heYInCfMLN16vY6FhQUcOnQIH330EU6fPo1arQbbttHpdDKd2EwQBGESgW/M\n1et15/9Op4O5uTm8//77Iz4U9mSRIAiCiI7Qg7lOp4Njx445Z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} ], "prompt_number": 32 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Training and testing\n", "\n", "Now, let's use the Sklearn function `train_test_split` to split the data into training and test data sets. If we use the entire set\n", "of data for the fitting and leave nothing for testing, we have no idea if we are simply \"overfitting\" the data. Think of the analogy of using a high order polynomial\n", "to fit data points on a graph, while it may fit the data perfectly, we learn nothing as it is a useless model for fitting subsequently generated data.\n", "\n", "The argument `test_size=0.5` splits the data into equal sized chunks for training and testing." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from sklearn.cross_validation import train_test_split\n", "\n", "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=3)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 33 }, { "cell_type": "code", "collapsed": false, "input": [ "print X_train.shape" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "(200, 21, 21)\n" ] } ], "prompt_number": 34 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's refit with the training data set only." ] }, { "cell_type": "code", "collapsed": false, "input": [ "model = MKSRegressionModel(Nbin=10)\n", "model.fit(X_train, y_train)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 35 }, { "cell_type": "markdown", "metadata": {}, "source": [ "How well does it predict?" ] }, { "cell_type": "code", "collapsed": false, "input": [ "'%1.3e' % mse(model.predict(X_test), y_test)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 36, "text": [ "'4.018e+09'" ] } ], "prompt_number": 36 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The above is just one way to split the data. We may want to check with alternative splits of the data. This is easy using Sklearn's `cross_validation` module. Here we do `10` different splits and check the mean and standard deviation of the mean square error." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from sklearn import cross_validation\n", "\n", "model = MKSRegressionModel(Nbin=10)\n", "scores = cross_validation.cross_val_score(model, X, y, score_func=mse, cv=20)\n", "print(\"MSE: %1.3e (+/- %1.3e)\" % (scores.mean(), scores.std()))" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "MSE: 3.946e+09 (+/- 2.568e+08)\n" ] } ], "prompt_number": 38 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `MKSRegressionModel` has methods inherited from the Sklearn's `LinearRegressionModel` that allows the use of `cross_validation`." ] }, { "cell_type": "code", "collapsed": false, "input": [ "??MKSRegressionModel.set_params" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `LinearRegressionModel` may not be the best class to inherit from. Fitting MKS into Sklearn needs careful consideration." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Optimize the `Nbin` hyperparameter\n", "\n", "`Nbin` is known as a hyperparameter. Hyperparameters are parameters that influence the fitting, but are separate from the data and the parameters used to generate the data.\n", "\n", "## Exercise 04-0\n", "\n", "Use all the data (`X` and `y`) to call `fit` for various values of `Nbin`. Calculate the mean square error by comparing the predicted data against the original data, `y`.\n", "\n", " - Do this for values of `Nbin` starting at 2 up to 100 with spacing of 10 using `np.arange`\n", " - What does the graph show?\n", " \n", "## Exercise 04-1\n", "\n", "Use the training data (`X_train`, `y_train`) to fit the MKS model and compare it with the test data. Plot the mean square error versus `Nbin`. Do this for all values of `Nbin` between 1 and 20.\n", "\n", "What is the optimum value of `Nbin`?" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import matplotlib.pyplot as plt\n", "\n", "mse = metrics.mean_squared_error\n", "\n", "Nbins = np.arange(2, 100, 10)\n", "\n", "errors = []\n", "\n", "for Nbin in Nbins:\n", " print Nbin\n", " model = MKSRegressionModel(Nbin=Nbin)\n", " model.fit(X, y)\n", " errors.append(mse(model.predict(X), y))\n", " \n", "plt.plot(Nbins, errors)\n", "plt.xlabel('Nbin')\n", "plt.ylabel('MSE')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "2\n", "12" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "22" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "32" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "42" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "52" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "62" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "72" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "82" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "92" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] }, { "metadata": {}, "output_type": "pyout", "prompt_number": 39, "text": [ "" ] }, { "metadata": {}, "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAYEAAAEPCAYAAACk43iMAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X10W/V9x/G3IDwujWUbCiulxYqB0VJiOSaUp9Ugx7Rl\nFLDzAKWkUCrHUJ5BjVPKIeyw5kGEjMKWOOKhgxEaW25gUOAkusOMAqMxkkuBAk2u4bBxGMOKBF2g\nkMT741eLOHZC7Fz5Srqf1zk+lXXFvd/c+vrr39P35xsYGBhAREQ8aS+3AxAREfcoCYiIeJiSgIiI\nhykJiIh4mJKAiIiHTXA7gHywbZtUKkU6nWbWrFmUlZW5HZKISEEqypbAvHnzhnzf1dWFZVnEYjEA\nVq5cyfTp02loaGDlypVuhCgiUhSKLgmsXLmSrq6u3PfJZBKAUCgEQCqVorKykv7+fjZu3Eh/f78r\ncYqIFIOiSwItLS0EAoHc9x0dHZSXlwMQCARIJBJEIhFs2yabzTJt2jS3QhURKXgFlwRSqRR9fX25\n7y3LIpvN7vTzmUyGioqK3Pf9/f2kUikymQzpdJqmpqa8xisiUswKbmA4GAwSi8VoaGjAtm2AzxzY\n3bHyRTAYJBgM5i1GEZFSkbeWQDQaHfH9WCxGLBajra1tp/9tOBxm8eLF2Lad6+vfGb/fTzqdBmDT\npk1UVla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i1ZsoTy8nIymQyBQIDm5uYh/01XVxe2befWdYgUKyUB8Tyfz0cg\nEGDmzJm5irfbVzAdyY5JQaRYqTtIBKitreX4448fsSb96tWraWxspK6uLle7Jx6P09bWhmVZzJw5\nk9bWVurq6jxR015Ki1oC4nmD6yWXL19OdXV1bhOkQdlslrVr1wJQXV2dK2kxqK+vj87OTrLZLFOn\nTtWqVSkqagmIbKe9vZ25c+cOeW/7pBAIBHLVK3c8XlZWlv8ARRymJCCyncFdq9rb23PvDW5xCabC\naVVVlafLF0tpUXeQeJ7P5xvSvbNixYohe2T7/X4aGxtJp9MsWbIk99/s7FwixUQF5EREPEzdQSIi\nHqYkICLiYUoCIiIepiQgIuJhSgIiIh6mJCAi4mH/D3rV/cIjxO0yAAAAAElFTkSuQmCC\n", "text": [ "" ] } ], "prompt_number": 39 }, { "cell_type": "code", "collapsed": false, "input": [ "errors = []\n", "\n", "Nbins = np.arange(2, 20)\n", "for Nbin in Nbins:\n", " model = MKSRegressionModel(Nbin=Nbin)\n", " model.fit(X_train, y_train)\n", " errors.append(mse(model.predict(X_test), y_test))\n", " \n", "plt.plot(Nbins, errors)\n", "plt.xlabel('Nbin')\n", "plt.ylabel('MSE')\n", "\n", "argmin = np.argmin(errors)\n", "print \"optimal Nbin: {0}, mse: {1:1.3e}\".format(Nbins[argmin], errors[argmin])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "optimal Nbin: 6, mse: 3.946e+09\n" ] }, { "metadata": {}, "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEPCAYAAABCyrPIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt823W9x/FXxsUbsKwZHkXgnKVdwQvSbAW8obVpq6LA\nke6C1yMcsg0VFLW2wwubRxgsHC+gbGuG53hD2iZ4kMdBXPODwuRyWJaMqRM29ivngRc8kjSFbYzb\ncv74tmHd2q7pkvxye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Yt24dS5cuHXNt/4Dwer0H7eY6ev/MmTMLX6BInigQRA5h9FjE\ndevWZa/tf5ykbdvMmTOnZM9XEJkqdRmJjMPlco3pAlq7du2YHUjdbjdtbW2kUilWr16d/Z6JHkuk\nHGhzOxERAdRlJCIiIxQIIiICKBBERGSEAkFERAAFgoiIjFAgiIgIAP8PKLpczOeQBYUAAAAASUVO\nRK5CYII=\n", "text": [ "" ] } ], "prompt_number": 40 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Training, validation and test data for hyperparameter optimization\n", "\n", "Using the test data to optimize hyperparameters leads to test data\n", "knowledge leaking into the model. A way to avoid this is to optimize\n", "the hyperparamters with a validation data set separate from the test\n", "data set. Sklearn provides `GridSearchCV` to automate the optimization\n", "of hyperparamters using only the training data without using the test\n", "data.\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from sklearn.grid_search import GridSearchCV\n", "\n", "parameters_to_tune = [{'Nbin': np.arange(2, 20)}]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 41 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make a scoring function. Highest score is best." ] }, { "cell_type": "code", "collapsed": false, "input": [ "def neg_mse(a, b):\n", " return -mse(a, b)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 42 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a `GridSearchCV` instance." ] }, { "cell_type": "code", "collapsed": false, "input": [ "gridSearch = GridSearchCV(MKSRegressionModel(Nbin=10), parameters_to_tune, cv=5, score_func=neg_mse)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 43 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Optimize with only the training data." ] }, { "cell_type": "code", "collapsed": false, "input": [ "??gridSearch.fit" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "gridSearch.fit(X_train, y_train)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 44, "text": [ "GridSearchCV(cv=5, estimator=MKSRegressionModel(Nbin=10), fit_params={},\n", " iid=True, loss_func=None, n_jobs=1,\n", " param_grid=[{'Nbin': array([ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,\n", " 19])}],\n", " pre_dispatch='2*n_jobs', refit=True,\n", " score_func=, verbose=0)" ] } ], "prompt_number": 44 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Find the best estimator." ] }, { "cell_type": "code", "collapsed": false, "input": [ "??gridSearch.score" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "print(gridSearch.best_estimator_)\n", "print gridSearch.score(X_test, y_test)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "MKSRegressionModel(Nbin=5)\n", "0.999989464884" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 45 }, { "cell_type": "markdown", "metadata": {}, "source": [ "What were the MSEs for each value of `Nbin`." ] }, { "cell_type": "code", "collapsed": false, "input": [ "for params, mean_score, scores in gridSearch.grid_scores_:\n", " print(\"%1.3e (+/-%1.3e) for %r\"% (mean_score, scores.std() / 2, params))" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "-4.149e+09 (+/-8.734e+07) for {'Nbin': 2}\n", "-4.177e+09 (+/-8.521e+07) for {'Nbin': 3}\n", "-3.979e+09 (+/-8.426e+07) for {'Nbin': 4}\n", "-3.970e+09 (+/-8.234e+07) for {'Nbin': 5}\n", "-3.990e+09 (+/-7.744e+07) for {'Nbin': 6}\n", "-4.010e+09 (+/-7.878e+07) for {'Nbin': 7}\n", "-4.032e+09 (+/-7.804e+07) for {'Nbin': 8}\n", "-4.062e+09 (+/-7.806e+07) for {'Nbin': 9}\n", "-4.089e+09 (+/-7.930e+07) for {'Nbin': 10}\n", "-4.117e+09 (+/-7.846e+07) for {'Nbin': 11}\n", "-4.144e+09 (+/-7.870e+07) for {'Nbin': 12}\n", "-4.170e+09 (+/-8.034e+07) for {'Nbin': 13}\n", "-4.199e+09 (+/-7.842e+07) for {'Nbin': 14}\n", "-4.221e+09 (+/-7.922e+07) for {'Nbin': 15}\n", "-4.245e+09 (+/-7.982e+07) for {'Nbin': 16}\n", "-4.281e+09 (+/-8.383e+07) for {'Nbin': 17}\n", "-4.313e+09 (+/-8.172e+07) for {'Nbin': 18}\n", "-4.334e+09 (+/-8.032e+07) for {'Nbin': 19}\n" ] } ], "prompt_number": 46 }, { "cell_type": "markdown", "metadata": {}, "source": [ "How does that match the test data?" ] }, { "cell_type": "code", "collapsed": false, "input": [ "y_true, y_pred = y_test, gridSearch.predict(X_test)\n", "'%1.3e' % mse(y_true, y_pred)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 47, "text": [ "'3.947e+09'" ] } ], "prompt_number": 47 }, { "cell_type": "markdown", "metadata": {}, "source": [ "What about for other values of `Nbin`." ] }, { "cell_type": "code", "collapsed": false, "input": [ "for Nbin in parameters_to_tune[0]['Nbin']:\n", " model = MKSRegressionModel(Nbin=Nbin)\n", " model.fit(X_train, y_train)\n", " y_true, y_pred = y_test, model.predict(X_test)\n", " print 'Nbin: {0}, mse: {1:1.3e}'.format(Nbin, mse(y_true, y_pred))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Another example from Sklearn's tutorial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `GridSearchCV` class can be used to search over multiple hyperparameters. This following example is from Sklearn's turorial. The scoring is very different between a classification problem and a " ] }, { "cell_type": "code", "collapsed": false, "input": [ "from sklearn import datasets\n", "\n", "digits = datasets.load_digits()\n", "\n", "print digits.data.shape\n", "\n", "for index, (image, label) in enumerate(zip(digits.images, digits.target)[:4]):\n", " plt.subplot(2, 4, index + 1)\n", " plt.axis('off')\n", " plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n", " plt.title('Training: %i' % label)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "(1797, 64)\n" ] }, { "metadata": {}, "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAWYAAABvCAYAAADfXmpqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACT1JREFUeJzt3TFTE90Xx/ET/NeS5BVAgjWRxB4ngRacIWBpoSSlhZJo\nhY0QKq00aGFt4qitJBFrQ8BeNr4BycYX4P0XDHmIDzx7BzbkLH4/M84YPdm9OcCPNe7hhowxRgAA\naowMewEAgH4EMwAoQzADgDIEMwAoQzADgDIDD+ZkMikjIyP/+nXlyhXrY7RaLUmlUr7VnUWr1ZJk\nMinRaFTy+fxAznEWl6W/R2ZmZqTdbg/0HLYuS29rtVrvtczOzqro72XpbaFQkGg06n9vzQXodrvG\ndV0TiURMvV433W7XdLtd6+e7rmtqtZpvdWcRDofNq1evjOu6JplMms3NzYGc5ywuQ3+3trbM8vKy\nCYVCpt1uD+QcZxH03nY6HRMKhcy7d+9Mt9s1hULBJJNJ389zFkHv7dbWlonH46bdbhvXdU02mzXZ\nbNaXY19IMB+JRCJmd3fXGGPM/v6+yWQyZmVlpfeJUi6XTSQSMaFQyCSTSeM4jjHGmJ2dnV7N/v6+\nmZqaMhsbGyYSiZh4PG5arVZfneM4p9YcP088HjflctnE4/He32UyGVMoFPrWffQBOFKr1dR8ch8X\n1P4aY8zGxobJ5XLqgvlIUHtbqVRMKpXqPT4Kak2C2lvHcXrr7nQ6ZmVlxeTzeV96MtT3mOv1uvz6\n9Uuq1aq4riv5fF4+f/4snU5HYrGYlMvlE5+3u7sroVBIDg4OJJPJSKFQsK5xHEeKxaI0Gg3Z2dmR\ncrksoVCo97xisSi3b9/uO5bjODI1NdV7nEwmxXEcP1owUEHpr4jIw4cP5eXLlxIOh3169YMVlN4u\nLCxIrVbrPW42mxKPx/1owcAEpbfj4+OSSCSkWq1KNBqV169f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MEMAMoQzACg\nDMEMAMoQzACgDMEMAMqEjDFm2IsAAPyDK2YAUIZgBgBlCGYAUIZgBgBlCGYAUIZgBgBlCGYAUIZg\nBgBlCGYAUIZgBgBlCGYAUIZgBgBlCGYAUIZgBgBlCGYAUIZgBgBlCGYAUOb/HJl0GVzletYAAAAA\nSUVORK5CYII=\n", "text": [ "" ] } ], "prompt_number": 48 }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.display import HTML\n", "HTML('')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "pyout", "prompt_number": 49, "text": [ "" ] } ], "prompt_number": 49 }, { "cell_type": "markdown", "metadata": {}, "source": [ "MKS is really prediciting a quantity. The above example is classification." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.display import Image\n", "Image(url='http://scikit-learn.org/stable/_static/ml_map.png', width=900)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "pyout", "prompt_number": 50, "text": [ "" ] } ], "prompt_number": 50 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }