Skip to content

Instantly share code, notes, and snippets.

@t00n t00n/urlablearning.ipynb Secret
Created Oct 12, 2016

Embed
What would you like to do?
{
"cells": [
{
"cell_type": "code",
"execution_count": 52,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import pandas as pd\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.svm import SVC\n",
"from sklearn.neighbors import KNeighborsClassifier\n",
"from datetime import datetime\n",
"import numpy as np\n",
"from math import floor\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline\n",
"\n",
"STARTS = [\n",
" datetime.strptime(\"14/09/2009\", \"%d/%m/%Y\"),\n",
" datetime.strptime(\"20/09/2010\", \"%d/%m/%Y\"),\n",
" datetime.strptime(\"15/09/2011\", \"%d/%m/%Y\"),\n",
" datetime.strptime(\"17/09/2012\", \"%d/%m/%Y\"),\n",
" datetime.strptime(\"16/09/2013\", \"%d/%m/%Y\"),\n",
" datetime.strptime(\"15/09/2014\", \"%d/%m/%Y\"),\n",
" datetime.strptime(\"14/09/2015\", \"%d/%m/%Y\"),\n",
" datetime.strptime(\"19/09/2016\", \"%d/%m/%Y\"),\n",
"]\n",
"\n",
"def week_no(instant):\n",
" yearstart = max([start for start in STARTS if start < instant])\n",
" delta = instant - yearstart\n",
" return floor(delta.days / 7)\n",
"\n",
"def datetime_to_timestamp(x):\n",
" return datetime.strptime(x[:16], \"%Y-%m-%d %H:%M\").timestamp()\n",
"\n",
"def features(x):\n",
" x = datetime.strptime(x[:16], \"%Y-%m-%d %H:%M\")\n",
" return np.array([x.weekday(), week_no(x), x.time().hour])\n",
"\n",
"def score(predictor, X, y):\n",
" p = predictor.predict(X)\n",
" return (predictor.predict_proba(X).max(axis=1) - 0.5)[p != np.array(y)].sum()\n"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df = pd.read_csv(\"openings.csv\")\n",
"\n",
"df['t'] = df['Unnamed: 0'].apply(pd.to_datetime)\n",
"df['weekday'] = df.t.dt.weekday\n",
"df['hour'] = df.t.dt.hour\n",
"df['month'] = df.t.dt.month\n",
"df['woy'] = df.t.dt.weekofyear\n",
"df['openlastweek'] = df.is_open.shift(24*7).fillna(False).astype(np.int32)\n",
"df['openlastday'] = df.is_open.shift(24).fillna(False).astype(np.int32)\n",
"df['openlasthour2'] = df.is_open.shift(2).fillna(False).astype(np.int32)\n",
"df['openlasthour'] = df.is_open.shift(1).fillna(False).astype(np.int32)\n",
"df['weekno'] = df.t.apply(week_no)\n",
"\n",
"X = df[['weekday', 'hour', 'openlastweek', 'openlastday', 'openlasthour2', 'openlasthour', 'weekno']]\n",
"y = df['is_open']\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=0)"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.95969353764157228"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lr = SVC()\n",
"lr.fit(X_train, y_train)\n",
"lr.score(X_test, y_test)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"16\n"
]
}
],
"source": [
"best = 0\n",
"best_i = 0\n",
"for i in range(1, 100):\n",
" knn = KNeighborsClassifier(i, n_jobs=-1)\n",
" knn.fit(X_train, y_train)\n",
" score = knn.score(X_test, y_test)\n",
" if score > best:\n",
" best = score\n",
" best_i = i\n",
" \n",
"print(best_i)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"219.5625\n"
]
}
],
"source": [
"knn = KNeighborsClassifier(16, n_jobs=-1)\n",
"knn.fit(X_train, y_train)\n",
"print(score(knn, X_test, y_test))"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(array([ 286., 462., 398., 348., 0., 301., 264., 245., 138., 34.]),\n",
" array([ 0. , 0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 ,\n",
" 0.45, 0.5 ]),\n",
" <a list of 10 Patch objects>)"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAg8AAAFkCAYAAACn/timAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAGWJJREFUeJzt3X+QXeV93/H3V5aRIiiyJ2shiNnEtQusf4xtbSBSE+Mm\niiGOGbseT1027IQf4zR2CfGodU3smgFD03HwBBECZtzUYwyyN/UIOzEDRcTQ4hiEoRIhpFzUNoYu\nwUhkDaxU4QWEnv5xzobVRUL7vXv3nr3L+zVzZvc+5zn3fM/DFfezzzn3niilIEmSNFtLmi5AkiT1\nF8ODJElKMTxIkqQUw4MkSUoxPEiSpBTDgyRJSjE8SJKkFMODJElKMTxIkqQUw4MkSUpJhYeIuDgi\n9rctD81YvywiromIiYjYExGbI2JV23McHxE3R8TeiNgZEZdHhCFGkqQ+sbSDbf4GWA9E/XjfjHVX\nAu8HPgLsBq4BbgTeA1CHhFuAHwFrgeOAG4Dngc91UIskSeqxyNwYKyIuBj5USllzkHVHA38PnFlK\n+XbddiLQAtaWUu6NiPcD3wGOLaVM1H1+G/gC8IZSyr7255UkSQtLJ6cL/klEPB4RfxsRmyLi+Lp9\nmGom4/bpjqWUHcA4sK5uWgs8OB0caluAlcDbOqhFkiT1WPa0xT3AOcAO4FjgEuB7EfF2YDXwfCll\nd9s2u+p11D93HWT99LoHDrbTiPhp4HTgUWAqWbMkSa9my4GfA7aUUn7cjSdMhYdSypYZD/8mIu4F\n/i/wUQ79ph7AbM6NvFKf04Gvz6pISZJ0MGcB3+jGE3VyweQ/KKVMRsT/At4CfBc4IiKObpt9WMVL\nsws7gZPbnuaY+m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ZSHjnIdnrJnP9/XkrZFxH3A2+Z7U4bP21RSnmB\n6oKk9dNt9YtoPXD3ITbbOrN/7X11uw6jwzHXHHQ65hHx74B/T/X17ffPd52LSRdf50uAZd2tbnHq\nYMxbVJ9qeRfVbM87ge8Ad9S/PzbPJfe9brzOI2IJ8HYyn6Rr+irR+srPjwI/AX4TOAn4MtVHpt5Q\nr78e+I8z+q8Dngf+DXAicAnVrbrf2vSx9MvSwZi/luof87uozrv/Qf34zU0fS78sHYz5p+vX9Yep\n/qqYXo5s+lj6ZelgzH8P+FXgTXX/fws8B5zb9LH0y5Id84Ns76ct5nnMgYuo/uB+E9VHO8eAvcBJ\ns93nQjhtQTn8jbLeCOyb0X9rRIwAv18v/xv4UCnlod5W3r+yYw4cB9zPS+fQPlUvdwK/0pOi+1wH\nY/4JqtC2ue2pPl8/hw6jgzE/Erimbv8J8DBwViml/b+BDqGDMdccdTDmrwf+E9UFlU9TzVysK6U8\nPNt9emMsSZKU0vg1D5Ikqb8YHiRJUorhQZIkpRgeJElSiuFBkiSlGB4kSVKK4UGSJKUYHiRJUorh\nQZIkpRgeJElSiuFBkiSl/H+k0dNDt/ugsAAAAABJRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x7f2e45058908>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"p = knn.predict(X)\n",
"plt.hist((knn.predict_proba(X).max(axis=1) - 0.5)[p != np.array(y)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.