Created
December 15, 2015 04:03
-
-
Save sbos/0b693abe8259c5ba442d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"from sklearn.neighbors import KNeighborsClassifier\n", | |
"from sklearn.cross_validation import cross_val_score\n", | |
"import matplotlib.pyplot as plt\n", | |
"%matplotlib inline" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<matplotlib.image.AxesImage at 0x10ad75d50>" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPwAAAD7CAYAAABOrvnfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD3hJREFUeJzt3X2MVfWdx/HPVxhiwEY03QUkbPWPrW6KCqziJtT0Zrc2\nVOID/7Bxs8mElGpitcS/VvljubNrYm2iMRuNySIS+hC2TQlUY9Kt1F5r0rRdiCIFu92NQ6IsDOxW\nVIwxYL77x5zB22Hmd+7cc8/D+H2/kgln7u88fO+Z8+Gce3/nwdxdAGK4qO4CAFSHwAOBEHggEAIP\nBELggUAIPBBIJYE3s7Vm9jsz+y8z+4cqljkTZnbUzF43s1fN7DcNqOdZMxszs0Ndr11uZi+a2e/N\n7KdmtrBh9bXN7O1sHb5qZmtrqm2Zmf3czA6b2W/N7JvZ641Yf4n6Kll/VnY/vJnNkfSfkr4s6Zik\n/5B0l7u/UeqCZ8DMRiX9pbv/oe5aJMnMbpZ0RtJ33P3a7LVvS/pfd/929p/mZe7+YI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B4IJBk4M1smZn93MwOm9lv\nzeyb2ettM3vbzF7NftZWUy6AIpL3pTezxZIWu/trZnaJpAOS7pS0QdL77v54YtpC96XPU/c9wevu\ng22Cpr/HQVzTn9L09zfVfemTJ964+wlJJ7LhM2b2hqSlE8vrr0wAden5M7yZXSlppaRfZS/db2YH\nzWy7mS0soTYAA9ZT4LPD+R9J2uzuZyQ9LekqSSskHZf0WGkVAhiY3HPpzWxI0m5J33P3vZLk7ie7\n2p+R9PxU07bb7fPDrVZLrVarWLUACsn70s4k7ZT0f+7+QNfrS9z9eDb8gKQb3f3vJk3Ll3YFpp8N\nmv4e+dLuwi/t8gL/RUm/kPS6pIkRt0i6S+OH8y5pVNI97j42aVoCX2D62aDp75HAzzDwBYsh8AWm\nnw2a/h4J/Ay75cpU9/XcTd8Y+A+nuLK3gQY8/33G8+bUWiAQAg8EQuCBQAg8EAiBBwIh8EAgBB4I\npNR++DL7ust+9naepveTV9HP3vS+fM5FuBB7eCAQAg8EQuCBQAh8ptPp1F1CEvVhEAh8pukbLPVh\nEAg8EAiBBwIp9QYYpcwYQE8qveMNgObhkB4IhMADgRB4IBACDwRC4IFA/h95vkPr91DqoAAAAABJ\nRU5ErkJggg==\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x107456e50>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPwAAAD7CAYAAABOrvnfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFG5JREFUeJzt3X9sVGW6B/DvgxSFtpZWfpRfChpWxUAwiBql7nhdNiyC\nvxK5etWQjYpGL2v468KaYPUG0TUY4z8qCoZ1N15lYbkYuV7Z1Ymt111lA8oKIiRQKNDys9hSfve5\nf3SopbTPM8zpzBx8v5/EODPfmXPenvZhzjnved8jqgoiCkOPfDeAiHKHBU8UEBY8UUBY8EQBYcET\nBYQFTxSQnBS8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LVu2mPn48ePNHAAuuugiMz98+LCZHzhwwMyjjqfP970HohI5qxv9DAsXLuwymzFjBuel\nJwodC54oICx4ooCw4IkCwoInCggLniggLHiigPxk++GtscKAP1Z7yJAhZv7666+buXfv8a1bt5q5\nNxa8paXFzL0+XK+fPp3x8N57mpubzbxPnz5mHvX+8N51AIWFhWa+a9cuM/fmJPDWX1NTY+bbt283\n80mTOo5a/xHvD09ELHiikLDgiQLCgicKCAueKCAseKKAsOCJApLVfvgHHnigy/zYsWPm571537/7\n7jszv+qqq8zc480Lv3z5cjOfMmWKmd93331m/uabb5p5bW2tmV999dVm7v3evTnnAX9eda+f2+vH\nLygoiJR71yJ4/fylpaVm7snn/ePZD09ELHiikLDgiQLCgicKCAueKCAseKKAsOCJApK38fAbN240\nP9+vXz8z79+/f0btSte+ffvM3JuT3evH9vqgvT5kj7f8Xr16mbk3Vhvw+/K939HRo0fNPOqYfe/z\nn376qZlPnjzZzOOM/fBExIInCgkLniggLHiigLDgiQLCgicKCAueKCBuP7yILAZwO4A9qjo69Vol\ngEcA7E29bY6qftThc+f1/eFfeuklM3/88cfN3OuH98Zye9IZr27x5oQ/cuSIuwyvnzuNvy0z9+Zl\n9+Z9v/TSS828Rw/7+87bRt69DwYNGmTmUTU1NXWZFRcXZ9wP/zaAjjPeK4CXVfXa1H8fdfI5IooZ\nt+BVtQrAwU6iaJeCEVHORTmGnykiX4vIIhGx79tERLHg30Csc68BeC71+D8BLADwcMc3VVZWtj1O\nJBJIJBIZro6ILFVVVaiqqnLfl1HBq+qe049F5C0AH3T2vvYFT0TZU1FRgYqKirbn8+fP7/R9Ge3S\ni0j70493A1ifyXKIKLfcb3gReRfAzwH0E5EdAJ4BkBCRsWg9W78VwGNZbSURdYvY3h/+wIEDZl5W\nVpbxsgF/TnJvznCvD9gb671z504z9+5f7401379/v5mXlJSY+fvvv2/mAHDLLbeYuXf/9IMHO+v8\n+ZF3/3fvWgFvzH9dXZ2Zjxgxwsx79+5t5p69e/eaeZQ5H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7d6+Ze39DkydPNvP58+eb+Zw5c8zcO+zxDnnGjx9v5jU1NWaeCV5aSxQQFjxRQFjw\nRAFhwRMFhAVPFBAWPFFAWPBEAcnbvPT5dr5flnk+WLp0qZnfe++9Zl5XV2fmXj+4dy1Fvi9/9q61\n8C4/t3BeeiJiwROFhAVPFJCcFXw6Y3XzqaqqKt9NMMV9+8W9fV988UW+m2DK1d8fCz6luro6300w\nxX37xb19LPhW3KUnCggLniggWe2Hz8qCiSgtnfXDZ63giSh+uEtPFBAWPFFAWPBEAWHBEwWEBU8U\nkP8Hrlc8fZYqyd0AAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x10a52ca90>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"train_data = np.load('train_data.npz')\n", | |
"validation_data = np.load('validation_data.npz')\n", | |
"\n", | |
"plt.matshow(train_data['X'][2224].reshape(28, 28), cmap=plt.get_cmap('Greys'))\n", | |
"plt.matshow(train_data['X'][2225].reshape(28, 28), cmap=plt.get_cmap('Greys'))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def test_classifier(cl, train_x, train_y):\n", | |
" print 'Train accuracy: ', cl.score(train_x, train_y)\n", | |
" print 'Cross-validation accuracy: ', cross_val_score(cl, train_x, train_y, cv=10).mean()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Train accuracy: 0.860515021459\n", | |
"Cross-validation accuracy: 0.824034334764\n" | |
] | |
} | |
], | |
"source": [ | |
"cl = KNeighborsClassifier()\n", | |
"cl.fit(train_data['X'], train_data['y'])\n", | |
"test_classifier(cl, train_data['X'], train_data['y'])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"train_x = train_data['X'][1950:].copy()\n", | |
"train_y = train_data['y'][1950:].copy()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Train accuracy: 0.505263157895\n", | |
"Cross-validation accuracy: 0.305263157895\n" | |
] | |
} | |
], | |
"source": [ | |
"cl = KNeighborsClassifier()\n", | |
"cl.fit(train_x, train_y)\n", | |
"test_classifier(cl, train_x, train_y)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<matplotlib.image.AxesImage at 0x10f148490>" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPwAAAD7CAYAAABOrvnfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADXtJREFUeJzt3V+oHOd5x/Hv09i9SBxQjVtZGDnyRUNKMViUhkJcvNAS\nFAquc6Pi3ohSgi9Sx/iqTi6ipb0oBGxMbwwlclCa4MbERLELbeMEL/ZN4jr4j5LY/QMWxKklt41N\nrTu3PL04I/nk/NlZ7ezszOr5fmDRnD07O8/OmZ/e2XnnnYnMRFINvzR0AZLWx8BLhRh4qRADLxVi\n4KVCDLxUyFoCHxHHIuK1iPi3iPjzdSzzSkTEuYh4JSJejIjnR1DPoxFxISLObnvu+oh4OiL+NSK+\nExEHRlbfNCLeaNbhixFxbKDaDkfEMxHx44j4UUR8rnl+FOtvTn1rWX/Rdz98RHwA+Bfg94GfAf8M\n3J2Zr/a64CsQEa8Dv5WZPx+6FoCI+F3gIvDVzLy1ee5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SIgZcKMfBSIf8PFAUJI8nbn00A\nAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x10623c7d0>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPwAAAD7CAYAAABOrvnfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADS1JREFUeJzt3U+oXOd5x/Hv09hdJA4oxokkjB150ZKNwaY0m7h4oCUo\nFFxno+JuRCjBi9YxWcXJIrrQRcFgY7oJlMhBaYIbExPHLrSNUzzYm8S18b8kdtqCBXEiyUljU2uX\nlqeLeyTfXOnOjObMmffMfb4fGDR3Zs6c9773/PS+57znPScyE0k1/E7rAkhaHwMvFWLgpUIMvFSI\ngZcKMfBSIWsJfEQcjYjXI+I/I+IL61jnlYiI0xHxSkS8GBHPjaA8D0fEuYh4dcdr10bEUxHxHxHx\nvYg4MLLybUXEm10dvhgRRxuV7YaIeDoifhwRP4qIz3Wvj6L+ZpRvLfUXQ4/DR8T7gJ8CfwL8HPh3\n4K7MfG3QFV+BiHgD+IPM/HXrsgBExB8B54GvZ+bN3Wv3A7/KzPu7/zQ/lJn3jah8J4B3M/PBFmXa\nUbZDwKHMfCkirgFeAO4EPsMI6m9G+Y6xhvpbRwv/ceC/MvN0Zv4G+Efgz9aw3isVrQtwQWY+C7y9\n6+U7gFPd81NsbyRN7FE+GEEdZubZzHype34eeA24npHU34zywRrqbx2Bvx742Y6f3+S9X3AsEvh+\nRDwfEZ9tXZg9HMzMc93zc8DBloXZwz0R8XJEnGy5y3FBRBwBbgV+yAjrb0f5ftC9NHj9rSPwm3Du\n7icy81bgU8BfdV3W0crt/bCx1etXgJuAW4AzwAMtC9N1lx8D7s3Md3e+N4b668r3bbbLd5411d86\nAv9z4IYdP9/Adis/Gpl5pvv3l8B32N4NGZtz3f4fEXEYeKtxeX5LZr6VHeCrNKzDiL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cSX3MvD98RBwCDmXmSxFxDfACcCdwDHg3Mx+csezMQci+Y6CtxzjHXr6+\nFhmDbv07bvrfYMhx/oi47P3hZ554k5lngbPd8/MR8Rpw/YXvXL6oklpYeB8+Io4AtwI/6F66JyJe\njoiTEXFggLJJWrGFAt91578N3JuZ54GvADcBtwBngAcGK6GklZl7Ln1EXA08BnwjMx8HyMy3drz/\nVeDJwUooaa7pdMp0Op37uXkH7QI4Bfx3Zn5+x+uHM/NM9/zzwB9m5l/sWtaDdhvMg3bDa3HQbl7g\nbwOeAV4BLnzwS8BdbHfnE3gDuDszz+1a1sBvMAM/vNEFvg8DP+6NbR4DP7zRDcsNaehrmu/3/1CG\n1vr3h+HroPU2NPR8/Mvx1FqpEAMvFWLgpUIMvFSIgZcKMfBSIQZeKqTZdenH/N1jWH/r328VWp/r\nMPT6N/HeBbbwUiEGXirEwEuFrC3wi8zV1d7GXn9jL5+2GfgNMfb6G3v5tM0uvVSIgZcKaXYBDEnD\nWusVbySNj116qRADLxVi4KVCDLxUiIGXCvl/rbSEBck/WFsAAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x10b6435d0>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"def binarize(x):\n", | |
" x[x > 0] = 255\n", | |
" return x\n", | |
"\n", | |
"train_x = binarize(train_x)\n", | |
"validation_x = binarize(validation_data['X']) # not forgetting about preprocessing validation data\n", | |
"\n", | |
"plt.matshow(train_x[2224 - 1950].reshape(28, 28), cmap=plt.get_cmap('Greys'))\n", | |
"plt.matshow(train_x[2225 - 1950].reshape(28, 28), cmap=plt.get_cmap('Greys'))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Train accuracy: 0.823684210526\n", | |
"Cross-validation accuracy: 0.726315789474\n" | |
] | |
} | |
], | |
"source": [ | |
"cl = KNeighborsClassifier()\n", | |
"cl.fit(train_x, train_y)\n", | |
"test_classifier(cl, train_x, train_y)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"fout = open('answer.csv', 'w')\n", | |
"fout.write('id,answer\\n')\n", | |
"\n", | |
"i = 0\n", | |
"for y in cl.predict(validation_x):\n", | |
" fout.write('%d,%d\\n' % (i, y))\n", | |
" i += 1\n", | |
"\n", | |
"fout.close()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment