Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"cells": [
{
"cell_type": "code",
"execution_count": 146,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"from sknn.mlp import Layer, Classifier\n",
"from sklearn.ensemble import RandomForestClassifier"
]
},
{
"cell_type": "code",
"execution_count": 147,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = pd.read_csv('openings.csv')"
]
},
{
"cell_type": "code",
"execution_count": 148,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"nn = Classifier(\n",
" layers=[\n",
" Layer(\"Sigmoid\", units=100),\n",
" Layer(\"Softmax\")],\n",
" loss_type='mcc',\n",
" learning_rate=0.001,\n",
" n_iter=1)"
]
},
{
"cell_type": "code",
"execution_count": 149,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df['t'] = df['Unnamed: 0'].apply(pd.to_datetime)"
]
},
{
"cell_type": "code",
"execution_count": 150,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"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)"
]
},
{
"cell_type": "code",
"execution_count": 151,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(27289, 8) (27289, 1)\n",
"[22 8 0 0 0 0 5 35]\n"
]
},
{
"data": {
"text/plain": [
"['hour',\n",
" 'month',\n",
" 'openlastday',\n",
" 'openlasthour',\n",
" 'openlasthour2',\n",
" 'openlastweek',\n",
" 'weekday',\n",
" 'woy']"
]
},
"execution_count": 151,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Xtr = np.array(df[sorted(list(set(df.columns) ^ set(['id', 'Unnamed: 0', 'is_open', 't'])))])\n",
"ytr = np.array(df['is_open'], dtype=np.int32).reshape(Xtr.shape[0], 1)\n",
"print(Xtr.shape, ytr.shape)\n",
"print(Xtr[0])\n",
"sorted(list(set(df.columns) ^ set(['id', 'Unnamed: 0', 'is_open', 't'])))"
]
},
{
"cell_type": "code",
"execution_count": 152,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#nn.fit(Xtr, ytr)"
]
},
{
"cell_type": "code",
"execution_count": 153,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/fhennecker/Documents/ulb/urlab/neurowed/ve/lib/python3.5/site-packages/ipykernel/__main__.py:4: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().\n"
]
},
{
"data": {
"text/plain": [
"RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',\n",
" max_depth=None, max_features='auto', max_leaf_nodes=None,\n",
" min_impurity_split=1e-07, min_samples_leaf=1,\n",
" min_samples_split=2, min_weight_fraction_leaf=0.0,\n",
" n_estimators=100, n_jobs=1, oob_score=False, random_state=None,\n",
" verbose=0, warm_start=False)"
]
},
"execution_count": 153,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rf = RandomForestClassifier(n_estimators=100)\n",
"from sklearn.model_selection import train_test_split\n",
"Xtraining, Xtest, ytraining, ytest = train_test_split(Xtr, ytr, test_size = 0.33) \n",
"rf.fit(Xtraining, ytraining)"
]
},
{
"cell_type": "code",
"execution_count": 154,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.95514101709971133"
]
},
"execution_count": 154,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rf.score(Xtest, ytest)"
]
},
{
"cell_type": "code",
"execution_count": 155,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"119.73445238095238"
]
},
"execution_count": 155,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def score(predictor, X, y):\n",
" p = predictor.predict(X)\n",
" return (predictor.predict_proba(X).max(axis=1) - 0.5)[p != y.flatten()].sum()\n",
"\n",
"score(rf, Xtest, ytest)"
]
},
{
"cell_type": "code",
"execution_count": 156,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(array([ 32., 36., 35., 38., 23., 17., 40., 36., 42., 105.]),\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": 156,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAg8AAAFkCAYAAACn/timAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAGD9JREFUeJzt3X+QZWV95/H3dxx+7GDNQIXAxLgohnVsd1NgjwFnEyRx\nYghxYySpjVzoMguFaxQM1cYFKaWCkqSUlDRRMSGaMioDFkEToEIxUcyi8ssVRqzShsQVtkWYYdsZ\nRMARYb7545xO7lymZ/q5fc69fXver6pTM/c5z733e5+5M/2Z5zznnMhMJEmSFmrFsAuQJEmjxfAg\nSZKKGB4kSVIRw4MkSSpieJAkSUUMD5IkqYjhQZIkFTE8SJKkIoYHSZJUxPAgSZKKFIeHiDgxIm6I\niO9FxK6IeH3XvpUR8YGI+EZEPFH3+WRE/EzPaxwWEZsi4gcRsSMiPh4RhzTxgSRJUrv6mXk4BPg6\ncA7Qe2OMVcBxwHuBVwCnAuuA63v6XQ2MARuB1wGvBq7soxZJkjRgsZgbY0XELuANmXnDXvq8ErgL\neFFmPhQRY8A3gfWZuaXuczLwD8ALM3Nr3wVJkqTWDWLNw6FUMxSP1Y9fBeyY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59jrkXod8wj4n8B76a6fPuWtutcThr8nq8ADmq2uuWpjzGfpjqr\n5Tiq2Z5jgRuAL9a//27LJY+8Jr7nEbEC+C+UnEk37FWi9crP3wV+BLwJeBlwJdUpUz9d7/8U8Kdd\n/TcATwPvANYBF1Pdqvvlw/4so7L1MeYHUP1lPo7quPsH6sc/N+zPMipbH2N+fv29PpXqfxVz2yHD\n/iyjsvUx5u8CfhU4uu7/h8CPgTOH/VlGZSsd8z0837MtWh5z4CKq/3AfTXVq5zXAk8DLFvqeS+Gw\nBbnvG2W9EHimq/8dEdEB/qTe/gX4rcz81mArH12lYw68ANjCvx9De2e93Qq8ZiBFj7g+xvytVKHt\nup6Xem/9GtqHPsb8EOCKuv1HwH3AGZnZ+2egefQx5lqkPsb8MOCvqBZU7qCaudiQmfct9D29MZYk\nSSoy9DUPkiRptBgeJElSEcODJEkqYniQJElFDA+SJKmI4UGSJBUxPEiSpCKGB0mSVMTwIEmSihge\nJElSEcODJEkq8q8e53vmHB6g0wAAAABJRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x116a5bf28>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"p = rf.predict(Xtest)\n",
"plt.hist((rf.predict_proba(Xtest).max(axis=1) - 0.5)[p != ytest.flatten()])"
]
},
{
"cell_type": "code",
"execution_count": 157,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.11167977, 0.02713162, 0.05992564, 0.41686455, 0.18582091,\n",
" 0.06844707, 0.05183866, 0.07829178])"
]
},
"execution_count": 157,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rf.feature_importances_"
]
},
{
"cell_type": "code",
"execution_count": 158,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"41"
]
},
"execution_count": 158,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.to_datetime('2016-10-12 22:00').weekofyear"
]
},
{
"cell_type": "code",
"execution_count": 159,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([1], dtype=int32)"
]
},
"execution_count": 159,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#['hour', 'month', 'openlastday', 'openlasthour', 'openlasthour2', 'openlastweek', 'weekday', 'woy']\n",
"from datetime import datetime\n",
"rf.predict(np.array([[2, 10, 1, 1, 1, 1, 2, pd.to_datetime('2016-10-12 22:00').weekofyear]]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"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
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.