<NME> Main PyLogit Example.ipynb <BEF> { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# pyLogit Example\n", "The purpose of this notebook is to demonstrate they key functionalities of pyLogit:\n", "<ol>\n", " <li> Converting data between 'wide' and 'long' formats. </li>\n", " <li> Estimating conditional logit models. </li>\n", "</ol>\n", "\n", "The dataset being used for this example is the \"Swissmetro\" dataset used in the Python Biogeme examples. The data can be downloaded at <a href=\"http://biogeme.epfl.ch/examples_swissmetro.html\">http://biogeme.epfl.ch/examples_swissmetro.html</a>, and a detailed explanation of the variables and data-collection procedure can be found at http://www.strc.ch/conferences/2001/bierlaire1.pdf.\n", "\n", "Relevant information about this dataset is that it is from a stated preference survey about whether or not individuals would use a new underground Magnetic-Levetation train system called the Swissmetro. \n", "\n", "The overall set of possible choices in this dataset was \"Train\", \"Swissmetro\", and \"Car.\" However, the choice set faced by each individual is <strong><u>not</u></strong> constant. An individual's choice set was partially based on the alternatives that he/she was capable of using at the moment. For instance, people who did not own cars did not receive a stated preference question where car was an alternative that they could choose. Note that because the choice set varies across choice situations, mlogit and statsmodels could not be used with this dataset. \n", "\n", "Also, each individual responded to multiple choice situations. Thus the choice observations are not truly independent of all other choice observations (they are correlated accross choices made by the same individual). However, for the purposes of this example, the effect of repeat-observations on the typical i.i.d. assumptions will be ignored.\n", "\n", "Based on the Swissmetro data, we will build a travel mode choice model for individuals who are commuting or going on a business trip." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from collections import OrderedDict # For recording the model specification \n", "\n", "import pandas as pd # For file input/output\n", "import numpy as np # For vectorized math operations\n", "\n", "import pylogit as pl # For MNL model estimation and\n", " # conversion from wide to long format\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load and filter the raw Swiss Metro data" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Note that the .dat files used by python biogeme are tab delimited text files\n", "wide_swiss_metro = pd.read_table(\"../data/swissmetro.dat\", sep=\"\\t\")\n", "\n", "# Select obervations whose choice is known (i.e. CHOICE != 0)\n", "# **AND** whose PURPOSE is either 1 (commute) or 3 (business)\n", "include_criteria = (wide_swiss_metro.PURPOSE.isin([1, 3]) &\n", " (wide_swiss_metro.CHOICE != 0))\n", "# Note that the .copy() ensures that any later changes are made \n", "# to a copy of the data and not to the original data\n", "wide_swiss_metro = wide_swiss_metro.loc[include_criteria].copy()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<div>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>0</th>\n", " <th>1</th>\n", " <th>2</th>\n", " <th>3</th>\n", " <th>4</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>GROUP</th>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " </tr>\n", " <tr>\n", " <th>SURVEY</th>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>SP</th>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>ID</th>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>PURPOSE</th>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>FIRST</th>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>TICKET</th>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>WHO</th>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>LUGGAGE</th>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>AGE</th>\n", " <td>3</td>\n", " <td>3</td>\n", " <td>3</td>\n", " <td>3</td>\n", " <td>3</td>\n", " </tr>\n", " <tr>\n", " <th>MALE</th>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>INCOME</th>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " </tr>\n", " <tr>\n", " <th>GA</th>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>ORIGIN</th>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " </tr>\n", " <tr>\n", " <th>DEST</th>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>TRAIN_AV</th>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>CAR_AV</th>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>SM_AV</th>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>TRAIN_TT</th>\n", " <td>112</td>\n", " <td>103</td>\n", " <td>130</td>\n", " <td>103</td>\n", " <td>130</td>\n", " </tr>\n", " <tr>\n", " <th>TRAIN_CO</th>\n", " <td>48</td>\n", " <td>48</td>\n", " <td>48</td>\n", " <td>40</td>\n", " <td>36</td>\n", " </tr>\n", " <tr>\n", " <th>TRAIN_HE</th>\n", " <td>120</td>\n", " <td>30</td>\n", " <td>60</td>\n", " <td>30</td>\n", " <td>60</td>\n", " </tr>\n", " <tr>\n", " <th>SM_TT</th>\n", " <td>63</td>\n", " <td>60</td>\n", " <td>67</td>\n", " <td>63</td>\n", " <td>63</td>\n", " </tr>\n", " <tr>\n", " <th>SM_CO</th>\n", " <td>52</td>\n", " <td>49</td>\n", " <td>58</td>\n", " <td>52</td>\n", " <td>42</td>\n", " </tr>\n", " <tr>\n", " <th>SM_HE</th>\n", " <td>20</td>\n", " <td>10</td>\n", " <td>30</td>\n", " <td>20</td>\n", " <td>20</td>\n", " </tr>\n", " <tr>\n", " <th>SM_SEATS</th>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>CAR_TT</th>\n", " <td>117</td>\n", " <td>117</td>\n", " <td>117</td>\n", " <td>72</td>\n", " <td>90</td>\n", " </tr>\n", " <tr>\n", " <th>CAR_CO</th>\n", " <td>65</td>\n", " <td>84</td>\n", " <td>52</td>\n", " <td>52</td>\n", " <td>84</td>\n", " </tr>\n", " <tr>\n", " <th>CHOICE</th>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " 0 1 2 3 4\n", "GROUP 2 2 2 2 2\n", "SURVEY 0 0 0 0 0\n", "SP 1 1 1 1 1\n", "ID 1 1 1 1 1\n", "PURPOSE 1 1 1 1 1\n", "FIRST 0 0 0 0 0\n", "TICKET 1 1 1 1 1\n", "WHO 1 1 1 1 1\n", "LUGGAGE 0 0 0 0 0\n", "AGE 3 3 3 3 3\n", "MALE 0 0 0 0 0\n", "INCOME 2 2 2 2 2\n", "GA 0 0 0 0 0\n", "ORIGIN 2 2 2 2 2\n", "DEST 1 1 1 1 1\n", "TRAIN_AV 1 1 1 1 1\n", "CAR_AV 1 1 1 1 1\n", "SM_AV 1 1 1 1 1\n", "TRAIN_TT 112 103 130 103 130\n", "TRAIN_CO 48 48 48 40 36\n", "TRAIN_HE 120 30 60 30 60\n", "SM_TT 63 60 67 63 63\n", "SM_CO 52 49 58 52 42\n", "SM_HE 20 10 30 20 20\n", "SM_SEATS 0 0 0 0 0\n", "CAR_TT 117 117 117 72 90\n", "CAR_CO 65 84 52 52 84\n", "CHOICE 2 2 2 2 2" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Look at the first 5 rows of the data\n", "wide_swiss_metro.head().T" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Convert the Swissmetro data to \"Long Format\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "pyLogit only estimates models using data that is in \"long\" format. \n", "\n", "Long format has 1 row per individual per available alternative, and wide format has 1 row per individual or observation. Long format is useful because it permits one to directly use matrix dot products to calculate the index, $V_{ij} = x_{ij} \\beta$, for each individual $\\left(i \\right)$ for each alternative $\\left(j \\right)$. In applications where one creates one's own dataset, the dataset can usually be created in long format from the very beginning. However, in situations where a dataset is provided to you in wide format (as in the case of the Swiss Metro dataset), it will be necesssary to convert the data from wide format to long format.\n", "\n", "To convert the raw swiss metro data to long format, we need to specify:\n", "<ol>\n", " <li>the variables or columns that are specific to a given individual, regardless of what alternative is being considered (note: every row is being treated as a separate observation, even though each individual gave multiple responses in this stated preference survey)</li>\n", " <li>the variables that vary across some or all alternatives, for a given individual (e.g. travel time)</li>\n", " <li>the availability variables</li>\n", " <li>the <u>unique</u> observation id column. (Note this dataset has an observation id column, but for the purposes of this example we don't want to consider the repeated observations of each person as being related. We therefore want a identifying column that gives an id to every response of every individual instead of to every individual).</li>\n", " <li>the choice column</li>\n", "</ol>\n", "<br>The cells below will identify these various columns, give them names in the long-format data, and perform the necessary conversion. \n", "\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Index([u'GROUP', u'SURVEY', u'SP', u'ID', u'PURPOSE', u'FIRST', u'TICKET',\n", " u'WHO', u'LUGGAGE', u'AGE', u'MALE', u'INCOME', u'GA', u'ORIGIN',\n", " u'DEST', u'TRAIN_AV', u'CAR_AV', u'SM_AV', u'TRAIN_TT', u'TRAIN_CO',\n", " u'TRAIN_HE', u'SM_TT', u'SM_CO', u'SM_HE', u'SM_SEATS', u'CAR_TT',\n", " u'CAR_CO', u'CHOICE'],\n", " dtype='object')" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Look at the columns of the swiss metro dataset\n", "wide_swiss_metro.columns" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Create the list of individual specific variables\n", "ind_variables = wide_swiss_metro.columns.tolist()[:15]\n", "\n", "# Specify the variables that vary across individuals and some or all alternatives\n", "# The keys are the column names that will be used in the long format dataframe.\n", "# The values are dictionaries whose key-value pairs are the alternative id and\n", "# the column name of the corresponding column that encodes that variable for\n", "# the given alternative. Examples below.\n", "alt_varying_variables = {u'travel_time': dict([(1, 'TRAIN_TT'),\n", " (2, 'SM_TT'),\n", " (3, 'CAR_TT')]),\n", " u'travel_cost': dict([(1, 'TRAIN_CO'),\n", " (2, 'SM_CO'),\n", " (3, 'CAR_CO')]),\n", " u'headway': dict([(1, 'TRAIN_HE'),\n", " (2, 'SM_HE')]),\n", " u'seat_configuration': dict([(2, \"SM_SEATS\")])}\n", "\n", "# Specify the availability variables\n", "# Note that the keys of the dictionary are the alternative id's.\n", "# The values are the columns denoting the availability for the\n", "# given mode in the dataset.\n", "availability_variables = {1: 'TRAIN_AV',\n", " 2: 'SM_AV', \n", " 3: 'CAR_AV'}\n", "\n", "##########\n", "# Determine the columns for: alternative ids, the observation ids and the choice\n", "##########\n", "# The 'custom_alt_id' is the name of a column to be created in the long-format data\n", "# It will identify the alternative associated with each row.\n", "custom_alt_id = \"mode_id\"\n", "\n", "# Create a custom id column that ignores the fact that this is a \n", "# panel/repeated-observations dataset. Note the +1 ensures the id's start at one.\n", "obs_id_column = \"custom_id\"\n", "wide_swiss_metro[obs_id_column] = np.arange(wide_swiss_metro.shape[0],\n", " dtype=int) + 1\n", "\n", "\n", "# Create a variable recording the choice column\n", "choice_column = \"CHOICE\"" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<div>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>0</th>\n", " <th>1</th>\n", " <th>2</th>\n", " <th>3</th>\n", " <th>4</th>\n", " <th>5</th>\n", " <th>6</th>\n", " <th>7</th>\n", " <th>8</th>\n", " <th>9</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>custom_id</th>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>4.0</td>\n", " </tr>\n", " <tr>\n", " <th>mode_id</th>\n", " <td>1.0</td>\n", " <td>2.0</td>\n", " <td>3.0</td>\n", " <td>1.0</td>\n", " <td>2.0</td>\n", " <td>3.0</td>\n", " <td>1.0</td>\n", " <td>2.0</td>\n", " <td>3.0</td>\n", " <td>1.0</td>\n", " </tr>\n", " <tr>\n", " <th>CHOICE</th>\n", " <td>0.0</td>\n", " <td>1.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>1.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>1.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " </tr>\n", " <tr>\n", " <th>GROUP</th>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " </tr>\n", " <tr>\n", " <th>SURVEY</th>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " </tr>\n", " <tr>\n", " <th>SP</th>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " </tr>\n", " <tr>\n", " <th>ID</th>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " </tr>\n", " <tr>\n", " <th>PURPOSE</th>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " </tr>\n", " <tr>\n", " <th>FIRST</th>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " </tr>\n", " <tr>\n", " <th>TICKET</th>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " </tr>\n", " <tr>\n", " <th>WHO</th>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " </tr>\n", " <tr>\n", " <th>LUGGAGE</th>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " </tr>\n", " <tr>\n", " <th>AGE</th>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " <td>3.0</td>\n", " </tr>\n", " <tr>\n", " <th>MALE</th>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " </tr>\n", " <tr>\n", " <th>INCOME</th>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " </tr>\n", " <tr>\n", " <th>GA</th>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " </tr>\n", " <tr>\n", " <th>ORIGIN</th>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " <td>2.0</td>\n", " </tr>\n", " <tr>\n", " <th>DEST</th>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " <td>1.0</td>\n", " </tr>\n", " <tr>\n", " <th>seat_configuration</th>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " <td>0.0</td>\n", " </tr>\n", " <tr>\n", " <th>travel_time</th>\n", " <td>112.0</td>\n", " <td>63.0</td>\n", " <td>117.0</td>\n", " <td>103.0</td>\n", " <td>60.0</td>\n", " <td>117.0</td>\n", " <td>130.0</td>\n", " <td>67.0</td>\n", " <td>117.0</td>\n", " <td>103.0</td>\n", " </tr>\n", " <tr>\n", " <th>headway</th>\n", " <td>120.0</td>\n", " <td>20.0</td>\n", " <td>0.0</td>\n", " <td>30.0</td>\n", " <td>10.0</td>\n", " <td>0.0</td>\n", " <td>60.0</td>\n", " <td>30.0</td>\n", " <td>0.0</td>\n", " <td>30.0</td>\n", " </tr>\n", " <tr>\n", " <th>travel_cost</th>\n", " <td>48.0</td>\n", " <td>52.0</td>\n", " <td>65.0</td>\n", " <td>48.0</td>\n", " <td>49.0</td>\n", " <td>84.0</td>\n", " <td>48.0</td>\n", " <td>58.0</td>\n", " <td>52.0</td>\n", " <td>40.0</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " 0 1 2 3 4 5 6 7 \\\n", "custom_id 1.0 1.0 1.0 2.0 2.0 2.0 3.0 3.0 \n", "mode_id 1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 \n", "CHOICE 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 \n", "GROUP 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 \n", "SURVEY 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", "SP 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", "ID 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", "PURPOSE 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", "FIRST 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", "TICKET 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", "WHO 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", "LUGGAGE 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", "AGE 3.0 3.0 3.0 3.0 3.0 3.0 3.0 3.0 \n", "MALE 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", "INCOME 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 \n", "GA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", "ORIGIN 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 \n", "DEST 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", "seat_configuration 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", "travel_time 112.0 63.0 117.0 103.0 60.0 117.0 130.0 67.0 \n", "headway 120.0 20.0 0.0 30.0 10.0 0.0 60.0 30.0 \n", "travel_cost 48.0 52.0 65.0 48.0 49.0 84.0 48.0 58.0 \n", "\n", " 8 9 \n", "custom_id 3.0 4.0 \n", "mode_id 3.0 1.0 \n", "CHOICE 0.0 0.0 \n", "GROUP 2.0 2.0 \n", "SURVEY 0.0 0.0 \n", "SP 1.0 1.0 \n", "ID 1.0 1.0 \n", "PURPOSE 1.0 1.0 \n", "FIRST 0.0 0.0 \n", "TICKET 1.0 1.0 \n", "WHO 1.0 1.0 \n", "LUGGAGE 0.0 0.0 \n", "AGE 3.0 3.0 \n", "MALE 0.0 0.0 \n", "INCOME 2.0 2.0 \n", "GA 0.0 0.0 \n", "ORIGIN 2.0 2.0 \n", "DEST 1.0 1.0 \n", "seat_configuration 0.0 0.0 \n", "travel_time 117.0 103.0 \n", "headway 0.0 30.0 \n", "travel_cost 52.0 40.0 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Perform the conversion to long-format\n", "long_swiss_metro = pl.convert_wide_to_long(wide_swiss_metro, \n", " ind_variables, \n", " alt_varying_variables, \n", " availability_variables, \n", " obs_id_column, \n", " choice_column,\n", " new_alt_id_name=custom_alt_id)\n", "# Look at the resulting long-format dataframe\n", "long_swiss_metro.head(10).T" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Perform desired variable creations and transformations\n", "Before estimating a model, one needs to pre-compute all of the variables that one wants to use. This is different from the functionality of other packages such as mlogit or statsmodels that use formula strings to create new variables \"on-the-fly.\" This is also somewhat different from Python Biogeme where new variables can be defined in the script but not actually created by the user before model estimation. pyLogit does not perform variable creation. It only estimates models using variables that already exist.\n", "\n", "Below, we pre-compute the variables needed for this example's model:\n", "<ol>\n", " <li> Travel time in hours instead of minutes. </li>\n", " <li> Travel cost in units of 0.01 CHF (swiss franks) instead of CHF, for ease of numeric optimization. </li>\n", " <li> Travel cost interacted with a variable that identifies individuals who own a season pass (and therefore have no marginal cost of traveling on the trip) or whose employer will pay for their commute/business trip. </li>\n", " <li> A dummy variable for traveling with a single piece of luggage. </li>\n", " <li> A dummy variable for traveling with multiple pieces of luggage. </li>\n", " <li> A dummy variable denoting whether an individual is traveling first class. </li>\n", " <li> A dummy variable indicating whether an individual took their survey on-board a train (since it is a-priori expected that these individuals are already willing to take a train or train-like service such as Swissmetro).</li>\n", "</ol>" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "##########\n", "# Create scaled variables so the estimated coefficients are of similar magnitudes\n", "##########\n", "# Scale the travel time column by 60 to convert raw units (minutes) to hours\n", "long_swiss_metro[\"travel_time_hrs\"] = long_swiss_metro[\"travel_time\"] / 60.0\n", "\n", "# Scale the headway column by 60 to convert raw units (minutes) to hours\n", "long_swiss_metro[\"headway_hrs\"] = long_swiss_metro[\"headway\"] / 60.0\n", "\n", "# Figure out who doesn't incur a marginal cost for the ticket\n", "# This can be because he/she owns an annual season pass (GA == 1) \n", "# or because his/her employer pays for the ticket (WHO == 2).\n", "# Note that all the other complexity in figuring out ticket costs\n", "# have been accounted for except the GA pass (the annual season\n", "# ticket). Make sure this dummy variable is only equal to 1 for\n", "# the rows with the Train or Swissmetro\n", "long_swiss_metro[\"free_ticket\"] = (((long_swiss_metro[\"GA\"] == 1) |\n", " (long_swiss_metro[\"WHO\"] == 2)) &\n", " long_swiss_metro[custom_alt_id].isin([1,2])).astype(int)\n", "# Scale the travel cost by 100 so estimated coefficients are of similar magnitude\n", "# and acccount for ownership of a season pass\n", "long_swiss_metro[\"travel_cost_hundreth\"] = (long_swiss_metro[\"travel_cost\"] *\n", " (long_swiss_metro[\"free_ticket\"] == 0) /\n", " 100.0)\n", "\n", "##########\n", "# Create various dummy variables to describe the choice context of a given\n", "# invidual for each choice task.\n", "##########\n", "# Create a dummy variable for whether a person has a single piece of luggage\n", "long_swiss_metro[\"single_luggage_piece\"] = (long_swiss_metro[\"LUGGAGE\"] == 1).astype(int)\n", "\n", "# Create a dummy variable for whether a person has multiple pieces of luggage\n", "long_swiss_metro[\"multiple_luggage_pieces\"] = (long_swiss_metro[\"LUGGAGE\"] == 3).astype(int)\n", "\n", "# Create a dummy variable indicating that a person is NOT first class\n", "long_swiss_metro[\"regular_class\"] = 1 - long_swiss_metro[\"FIRST\"]\n", "\n", "# Create a dummy variable indicating that the survey was taken aboard a train\n", "# Note that such passengers are a-priori imagined to be somewhat partial to train modes\n", "long_swiss_metro[\"train_survey\"] = 1 - long_swiss_metro[\"SURVEY\"]\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create the model specification\n", "The model specification being used in this example is the following:\n", "$$\n", "\\begin{aligned}\n", "V_{i, \\textrm{Train}} &= \\textrm{ASC Train} + \\\\\n", "&\\quad \\beta _{ \\textrm{tt_transit} } \\textrm{Travel Time} _{ \\textrm{Train}} * \\frac{1}{60} + \\\\\n", "&\\quad \\beta _{ \\textrm{tc_train} } \\textrm{Travel Cost}_{\\textrm{Train}} * \\left( GA == 0 \\right) * 0.01 + \\\\\n", "&\\quad \\beta _{ \\textrm{headway_train} } \\textrm{Headway} _{\\textrm{Train}} * \\frac{1}{60} + \\\\\n", "&\\quad \\beta _{ \\textrm{survey} } \\left( \\textrm{Train Survey} == 1 \\right) \\\\\n", "\\\\\n", "V_{i, \\textrm{Swissmetro}} &= \\textrm{ASC Swissmetro} + \\\\\n", "&\\quad \\beta _{ \\textrm{tt_transit} } \\textrm{Travel Time} _{ \\textrm{Swissmetro}} * \\frac{1}{60} + \\\\\n", "&\\quad \\beta _{ \\textrm{tc_sm} } \\textrm{Travel Cost}_{\\textrm{Swissmetro}} * \\left( GA == 0 \\right) * 0.01 + \\\\\n", "&\\quad \\beta _{ \\textrm{headway_sm} } \\textrm{Heaway} _{\\textrm{Swissmetro}} * \\frac{1}{60} + \\\\\n", "&\\quad \\beta _{ \\textrm{seat} } \\left( \\textrm{Seat Configuration} == 1 \\right) \\\\\n", "&\\quad \\beta _{ \\textrm{survey} } \\left( \\textrm{Train Survey} == 1 \\right) \\\\\n", "&\\quad \\beta _{ \\textrm{first_class} } \\left( \\textrm{First Class} == 0 \\right) \\\\\n", "\\\\\n", "V_{i, \\textrm{Car}} &= \\beta _{ \\textrm{tt_car} } \\textrm{Travel Time} _{ \\textrm{Car}} * \\frac{1}{60} + \\\\\n", "&\\quad \\beta _{ \\textrm{tc_car}} \\textrm{Travel Cost}_{\\textrm{Car}} * 0.01 + \\\\\n", "&\\quad \\beta _{\\textrm{luggage}=1} \\left( \\textrm{Luggage} == 1 \\right) + \\\\\n", "&\\quad \\beta _{\\textrm{luggage}>1} \\left( \\textrm{Luggage} > 1 \\right)\n", "\\end{aligned}\n", "$$\n", "\n", "Note that packages such as mlogit and statsmodels do not, by default, handle coefficients that vary over some alternatives but not all, such as the travel time coefficient that is specified as being the same for \"Train\" and \"Swissmetro\" but different for \"Car.\"" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# NOTE: - Specification and variable names must be ordered dictionaries.\n", "# - Keys should be variables within the long format dataframe.\n", "# The sole exception to this is the \"intercept\" key.\n", "# - For the specification dictionary, the values should be lists\n", "# of integers or lists of lists of integers. Within a list, \n", "# or within the inner-most list, the integers should be the \n", "# alternative ID's of the alternative whose utility specification \n", "# the explanatory variable is entering. Lists of lists denote \n", "# alternatives that will share a common coefficient for the variable\n", "# in question.\n", "\n", "basic_specification = OrderedDict()\n", "basic_names = OrderedDict()\n", "\n", "basic_specification[\"intercept\"] = [1, 2]\n", "basic_names[\"intercept\"] = ['ASC Train',\n", " 'ASC Swissmetro']\n", "\n", "basic_specification[\"travel_time_hrs\"] = [[1, 2,], 3]\n", "basic_names[\"travel_time_hrs\"] = ['Travel Time, units:hrs (Train and Swissmetro)',\n", " 'Travel Time, units:hrs (Car)']\n", "\n", "basic_specification[\"travel_cost_hundreth\"] = [1, 2, 3]\n", "basic_names[\"travel_cost_hundreth\"] = ['Travel Cost * (Annual Pass == 0), units: 0.01 CHF (Train)',\n", " 'Travel Cost * (Annual Pass == 0), units: 0.01 CHF (Swissmetro)',\n", " 'Travel Cost, units: 0.01 CHF (Car)']\n", "\n", "basic_specification[\"headway_hrs\"] = [1, 2]\n", "basic_names[\"headway_hrs\"] = [\"Headway, units:hrs, (Train)\",\n", " \"Headway, units:hrs, (Swissmetro)\"]\n", "\n", "basic_specification[\"seat_configuration\"] = [2]\n", "basic_names[\"seat_configuration\"] = ['Airline Seat Configuration, base=No (Swissmetro)']\n", "\n", "basic_specification[\"train_survey\"] = [[1, 2]]\n", "basic_names[\"train_survey\"] = [\"Surveyed on a Train, base=No, (Train and Swissmetro)\"]\n", "\n", "basic_specification[\"regular_class\"] = [1]\n", "basic_names[\"regular_class\"] = [\"First Class == False, (Swissmetro)\"]\n", "\n", "basic_specification[\"single_luggage_piece\"] = [3]\n", "basic_names[\"single_luggage_piece\"] = [\"Number of Luggage Pieces == 1, (Car)\"]\n", "\n", "basic_specification[\"multiple_luggage_pieces\"] = [3]\n", "basic_names[\"multiple_luggage_pieces\"] = [\"Number of Luggage Pieces > 1, (Car)\"]\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Estimate the conditional logit model" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Log-likelihood at zero: -6,964.6630\n", "Initial Log-likelihood: -6,964.6630\n", "Estimation Time: 0.10 seconds.\n", "Final log-likelihood: -5,159.2583\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/timothyb0912/anaconda/lib/python2.7/site-packages/scipy/optimize/_minimize.py:385: RuntimeWarning: Method BFGS does not use Hessian information (hess).\n", " RuntimeWarning)\n" ] }, { "data": { "text/html": [ "<table class=\"simpletable\">\n", "<caption>Multinomial Logit Model Regression Results</caption>\n", "<tr>\n", " <th>Dep. Variable:</th> <td>CHOICE</td> <th> No. Observations: </th> <td>6,768</td> \n", "</tr>\n", "<tr>\n", " <th>Model:</th> <td>Multinomial Logit Model</td> <th> Df Residuals: </th> <td>6,754</td> \n", "</tr>\n", "<tr>\n", " <th>Method:</th> <td>MLE</td> <th> Df Model: </th> <td>14</td> \n", "</tr>\n", "<tr>\n", " <th>Date:</th> <td>Tue, 30 Aug 2016</td> <th> Pseudo R-squ.: </th> <td>0.259</td> \n", "</tr>\n", "<tr>\n", " <th>Time:</th> <td>13:08:19</td> <th> Pseudo R-bar-squ.: </th> <td>0.257</td> \n", "</tr>\n", "<tr>\n", " <th>converged:</th> <td>True</td> <th> Log-Likelihood: </th> <td>-5,159.258</td>\n", "</tr>\n", "<tr>\n", " <th> </th> <td> </td> <th> LL-Null: </th> <td>-6,964.663</td>\n", "</tr>\n", "</table>\n", "<table class=\"simpletable\">\n", "<tr>\n", " <td></td> <th>coef</th> <th>std err</th> <th>z</th> <th>P>|z|</th> <th>[95.0% Conf. Int.]</th> \n", "</tr>\n", "<tr>\n", " <th>ASC Train</th> <td> -1.2929</td> <td> 0.146</td> <td> -8.845</td> <td> 0.000</td> <td> -1.579 -1.006</td>\n", "</tr>\n", "<tr>\n", " <th>ASC Swissmetro</th> <td> -0.5026</td> <td> 0.116</td> <td> -4.332</td> <td> 0.000</td> <td> -0.730 -0.275</td>\n", "</tr>\n", "<tr>\n", " <th>Travel Time, units:hrs (Train and Swissmetro)</th> <td> -0.6990</td> <td> 0.042</td> <td> -16.545</td> <td> 0.000</td> <td> -0.782 -0.616</td>\n", "</tr>\n", "<tr>\n", " <th>Travel Time, units:hrs (Car)</th> <td> -0.7230</td> <td> 0.047</td> <td> -15.340</td> <td> 0.000</td> <td> -0.815 -0.631</td>\n", "</tr>\n", "<tr>\n", " <th>Travel Cost * (Annual Pass == 0), units: 0.01 CHF (Train)</th> <td> -0.5618</td> <td> 0.094</td> <td> -6.002</td> <td> 0.000</td> <td> -0.745 -0.378</td>\n", "</tr>\n", "<tr>\n", " <th>Travel Cost * (Annual Pass == 0), units: 0.01 CHF (Swissmetro)</th> <td> -0.2817</td> <td> 0.045</td> <td> -6.252</td> <td> 0.000</td> <td> -0.370 -0.193</td>\n", "</tr>\n", "<tr>\n", " <th>Travel Cost, units: 0.01 CHF (Car)</th> <td> -0.5139</td> <td> 0.104</td> <td> -4.953</td> <td> 0.000</td> <td> -0.717 -0.311</td>\n", "</tr>\n", "<tr>\n", " <th>Headway, units:hrs, (Train)</th> <td> -0.3143</td> <td> 0.062</td> <td> -5.063</td> <td> 0.000</td> <td> -0.436 -0.193</td>\n", "</tr>\n", "<tr>\n", " <th>Headway, units:hrs, (Swissmetro)</th> <td> -0.3773</td> <td> 0.196</td> <td> -1.925</td> <td> 0.054</td> <td> -0.761 0.007</td>\n", "</tr>\n", "<tr>\n", " <th>Airline Seat Configuration, base=No (Swissmetro)</th> <td> -0.7825</td> <td> 0.087</td> <td> -8.970</td> <td> 0.000</td> <td> -0.953 -0.611</td>\n", "</tr>\n", "<tr>\n", " <th>Surveyed on a Train, base=No, (Train and Swissmetro)</th> <td> 2.5425</td> <td> 0.114</td> <td> 22.235</td> <td> 0.000</td> <td> 2.318 2.767</td>\n", "</tr>\n", "<tr>\n", " <th>First Class == False, (Swissmetro)</th> <td> 0.5650</td> <td> 0.077</td> <td> 7.305</td> <td> 0.000</td> <td> 0.413 0.717</td>\n", "</tr>\n", "<tr>\n", " <th>Number of Luggage Pieces == 1, (Car)</th> <td> 0.4228</td> <td> 0.067</td> <td> 6.270</td> <td> 0.000</td> <td> 0.291 0.555</td>\n", "</tr>\n", "<tr>\n", " <th>Number of Luggage Pieces > 1, (Car)</th> <td> 1.4141</td> <td> 0.259</td> <td> 5.461</td> <td> 0.000</td> <td> 0.907 1.922</td>\n", "</tr>\n", "</table>" ], "text/plain": [ "<class 'statsmodels.iolib.summary.Summary'>\n", "\"\"\"\n", " Multinomial Logit Model Regression Results \n", "===================================================================================\n", "Dep. Variable: CHOICE No. Observations: 6,768\n", "Model: Multinomial Logit Model Df Residuals: 6,754\n", "Method: MLE Df Model: 14\n", "Date: Tue, 30 Aug 2016 Pseudo R-squ.: 0.259\n", "Time: 13:08:19 Pseudo R-bar-squ.: 0.257\n", "converged: True Log-Likelihood: -5,159.258\n", " LL-Null: -6,964.663\n", "==================================================================================================================================\n", " coef std err z P>|z| [95.0% Conf. Int.]\n", "----------------------------------------------------------------------------------------------------------------------------------\n", "ASC Train -1.2929 0.146 -8.845 0.000 -1.579 -1.006\n", "ASC Swissmetro -0.5026 0.116 -4.332 0.000 -0.730 -0.275\n", "Travel Time, units:hrs (Train and Swissmetro) -0.6990 0.042 -16.545 0.000 -0.782 -0.616\n", "Travel Time, units:hrs (Car) -0.7230 0.047 -15.340 0.000 -0.815 -0.631\n", "Travel Cost * (Annual Pass == 0), units: 0.01 CHF (Train) -0.5618 0.094 -6.002 0.000 -0.745 -0.378\n", "Travel Cost * (Annual Pass == 0), units: 0.01 CHF (Swissmetro) -0.2817 0.045 -6.252 0.000 -0.370 -0.193\n", "Travel Cost, units: 0.01 CHF (Car) -0.5139 0.104 -4.953 0.000 -0.717 -0.311\n", "Headway, units:hrs, (Train) -0.3143 0.062 -5.063 0.000 -0.436 -0.193\n", "Headway, units:hrs, (Swissmetro) -0.3773 0.196 -1.925 0.054 -0.761 0.007\n", "Airline Seat Configuration, base=No (Swissmetro) -0.7825 0.087 -8.970 0.000 -0.953 -0.611\n", "Surveyed on a Train, base=No, (Train and Swissmetro) 2.5425 0.114 22.235 0.000 2.318 2.767\n", "First Class == False, (Swissmetro) 0.5650 0.077 7.305 0.000 0.413 0.717\n", "Number of Luggage Pieces == 1, (Car) 0.4228 0.067 6.270 0.000 0.291 0.555\n", "Number of Luggage Pieces > 1, (Car) 1.4141 0.259 5.461 0.000 0.907 1.922\n", "==================================================================================================================================\n", "\"\"\"" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Estimate the multinomial logit model (MNL)\n", "swissmetro_mnl = pl.create_choice_model(data=long_swiss_metro,\n", " alt_id_col=custom_alt_id,\n", " obs_id_col=obs_id_column,\n", " choice_col=choice_column,\n", " specification=basic_specification,\n", " model_type=\"MNL\",\n", " names=basic_names)\n", "\n", "# Specify the initial values and method for the optimization.\n", "swissmetro_mnl.fit_mle(np.zeros(14))\n", "\n", "# Look at the estimation results\n", "swissmetro_mnl.get_statsmodels_summary()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## View results without using statsmodels summary table" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can view all of the results simply by using print_summaries(). This will simply print the various summary dataframes." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "Number of Parameters 14\n", "Number of Observations 6768\n", "Null Log-Likelihood -6964.66\n", "Fitted Log-Likelihood -5159.26\n", "Rho-Squared 0.259224\n", "Rho-Bar-Squared 0.257213\n", "Estimation Message Optimization terminated successfully.\n", "dtype: object\n", "==============================\n", " parameters std_err \\\n", "ASC Train -1.292943 0.146184 \n", "ASC Swissmetro -0.502595 0.116010 \n", "Travel Time, units:hrs (Train and Swissmetro) -0.699029 0.042250 \n", "Travel Time, units:hrs (Car) -0.722998 0.047130 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -0.561769 0.093593 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -0.281683 0.045058 \n", "Travel Cost, units: 0.01 CHF (Car) -0.513867 0.103745 \n", "Headway, units:hrs, (Train) -0.314336 0.062085 \n", "Headway, units:hrs, (Swissmetro) -0.377324 0.195969 \n", "Airline Seat Configuration, base=No (Swissmetro) -0.782455 0.087232 \n", "Surveyed on a Train, base=No, (Train and Swissm... 2.542475 0.114347 \n", "First Class == False, (Swissmetro) 0.565015 0.077341 \n", "Number of Luggage Pieces == 1, (Car) 0.422767 0.067424 \n", "Number of Luggage Pieces > 1, (Car) 1.414052 0.258917 \n", "\n", " t_stats p_values \\\n", "ASC Train -8.844625 9.183619e-19 \n", "ASC Swissmetro -4.332359 1.475204e-05 \n", "Travel Time, units:hrs (Train and Swissmetro) -16.545035 1.738624e-61 \n", "Travel Time, units:hrs (Car) -15.340414 4.105671e-53 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -6.002282 1.945634e-09 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -6.251572 4.063404e-10 \n", "Travel Cost, units: 0.01 CHF (Car) -4.953161 7.301745e-07 \n", "Headway, units:hrs, (Train) -5.063008 4.126931e-07 \n", "Headway, units:hrs, (Swissmetro) -1.925430 5.417557e-02 \n", "Airline Seat Configuration, base=No (Swissmetro) -8.969775 2.971216e-19 \n", "Surveyed on a Train, base=No, (Train and Swissm... 22.234822 1.581947e-109 \n", "First Class == False, (Swissmetro) 7.305494 2.762506e-13 \n", "Number of Luggage Pieces == 1, (Car) 6.270276 3.604088e-10 \n", "Number of Luggage Pieces > 1, (Car) 5.461402 4.723880e-08 \n", "\n", " robust_std_err \\\n", "ASC Train 0.302543 \n", "ASC Swissmetro 0.392238 \n", "Travel Time, units:hrs (Train and Swissmetro) 0.146476 \n", "Travel Time, units:hrs (Car) 0.164374 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... 0.128883 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... 0.066505 \n", "Travel Cost, units: 0.01 CHF (Car) 0.230016 \n", "Headway, units:hrs, (Train) 0.061189 \n", "Headway, units:hrs, (Swissmetro) 0.206538 \n", "Airline Seat Configuration, base=No (Swissmetro) 0.097108 \n", "Surveyed on a Train, base=No, (Train and Swissm... 0.351394 \n", "First Class == False, (Swissmetro) 0.078165 \n", "Number of Luggage Pieces == 1, (Car) 0.156215 \n", "Number of Luggage Pieces > 1, (Car) 0.493739 \n", "\n", " robust_t_stats \\\n", "ASC Train -4.273585 \n", "ASC Swissmetro -1.281352 \n", "Travel Time, units:hrs (Train and Swissmetro) -4.772303 \n", "Travel Time, units:hrs (Car) -4.398497 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -4.358752 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -4.235516 \n", "Travel Cost, units: 0.01 CHF (Car) -2.234049 \n", "Headway, units:hrs, (Train) -5.137165 \n", "Headway, units:hrs, (Swissmetro) -1.826904 \n", "Airline Seat Configuration, base=No (Swissmetro) -8.057613 \n", "Surveyed on a Train, base=No, (Train and Swissm... 7.235402 \n", "First Class == False, (Swissmetro) 7.228484 \n", "Number of Luggage Pieces == 1, (Car) 2.706309 \n", "Number of Luggage Pieces > 1, (Car) 2.863968 \n", "\n", " robust_p_values \n", "ASC Train 1.923545e-05 \n", "ASC Swissmetro 2.000702e-01 \n", "Travel Time, units:hrs (Train and Swissmetro) 1.821311e-06 \n", "Travel Time, units:hrs (Car) 1.090030e-05 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... 1.308061e-05 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... 2.280274e-05 \n", "Travel Cost, units: 0.01 CHF (Car) 2.547984e-02 \n", "Headway, units:hrs, (Train) 2.789139e-07 \n", "Headway, units:hrs, (Swissmetro) 6.771420e-02 \n", "Airline Seat Configuration, base=No (Swissmetro) 7.779883e-16 \n", "Surveyed on a Train, base=No, (Train and Swissm... 4.641533e-13 \n", "First Class == False, (Swissmetro) 4.884147e-13 \n", "Number of Luggage Pieces == 1, (Car) 6.803565e-03 \n", "Number of Luggage Pieces > 1, (Car) 4.183697e-03 \n" ] } ], "source": [ "# Look at other all results at the same time\n", "swissmetro_mnl.print_summaries()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Number of Parameters 14\n", "Number of Observations 6768\n", "Null Log-Likelihood -6964.66\n", "Fitted Log-Likelihood -5159.26\n", "Rho-Squared 0.259224\n", "Rho-Bar-Squared 0.257213\n", "Estimation Message Optimization terminated successfully.\n", "dtype: object" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Look at the general and goodness of fit statistics\n", "swissmetro_mnl.fit_summary" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<div>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>parameters</th>\n", " <th>std_err</th>\n", " <th>t_stats</th>\n", " <th>p_values</th>\n", " <th>robust_std_err</th>\n", " <th>robust_t_stats</th>\n", " <th>robust_p_values</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>ASC Train</th>\n", " <td>-1.293</td>\n", " <td>0.146</td>\n", " <td>-8.845</td>\n", " <td>0.000</td>\n", " <td>0.303</td>\n", " <td>-4.274</td>\n", " <td>0.000</td>\n", " </tr>\n", " <tr>\n", " <th>ASC Swissmetro</th>\n", " <td>-0.503</td>\n", " <td>0.116</td>\n", " <td>-4.332</td>\n", " <td>0.000</td>\n", " <td>0.392</td>\n", " <td>-1.281</td>\n", " <td>0.200</td>\n", " </tr>\n", " <tr>\n", " <th>Travel Time, units:hrs (Train and Swissmetro)</th>\n", " <td>-0.699</td>\n", " <td>0.042</td>\n", " <td>-16.545</td>\n", " <td>0.000</td>\n", " <td>0.146</td>\n", " <td>-4.772</td>\n", " <td>0.000</td>\n", " </tr>\n", " <tr>\n", " <th>Travel Time, units:hrs (Car)</th>\n", " <td>-0.723</td>\n", " <td>0.047</td>\n", " <td>-15.340</td>\n", " <td>0.000</td>\n", " <td>0.164</td>\n", " <td>-4.398</td>\n", " <td>0.000</td>\n", " </tr>\n", " <tr>\n", " <th>Travel Cost * (Annual Pass == 0), units: 0.01 CHF (Train)</th>\n", " <td>-0.562</td>\n", " <td>0.094</td>\n", " <td>-6.002</td>\n", " <td>0.000</td>\n", " <td>0.129</td>\n", " <td>-4.359</td>\n", " <td>0.000</td>\n", " </tr>\n", " <tr>\n", " <th>Travel Cost * (Annual Pass == 0), units: 0.01 CHF (Swissmetro)</th>\n", " <td>-0.282</td>\n", " <td>0.045</td>\n", " <td>-6.252</td>\n", " <td>0.000</td>\n", " <td>0.067</td>\n", " <td>-4.236</td>\n", " <td>0.000</td>\n", " </tr>\n", " <tr>\n", " <th>Travel Cost, units: 0.01 CHF (Car)</th>\n", " <td>-0.514</td>\n", " <td>0.104</td>\n", " <td>-4.953</td>\n", " <td>0.000</td>\n", " <td>0.230</td>\n", " <td>-2.234</td>\n", " <td>0.025</td>\n", " </tr>\n", " <tr>\n", " <th>Headway, units:hrs, (Train)</th>\n", " <td>-0.314</td>\n", " <td>0.062</td>\n", " <td>-5.063</td>\n", " <td>0.000</td>\n", " <td>0.061</td>\n", " <td>-5.137</td>\n", " <td>0.000</td>\n", " </tr>\n", " <tr>\n", " <th>Headway, units:hrs, (Swissmetro)</th>\n", " <td>-0.377</td>\n", " <td>0.196</td>\n", " <td>-1.925</td>\n", " <td>0.054</td>\n", " <td>0.207</td>\n", " <td>-1.827</td>\n", " <td>0.068</td>\n", " </tr>\n", " <tr>\n", " <th>Airline Seat Configuration, base=No (Swissmetro)</th>\n", " <td>-0.782</td>\n", " <td>0.087</td>\n", " <td>-8.970</td>\n", " <td>0.000</td>\n", " <td>0.097</td>\n", " <td>-8.058</td>\n", " <td>0.000</td>\n", " </tr>\n", " <tr>\n", " <th>Surveyed on a Train, base=No, (Train and Swissmetro)</th>\n", " <td>2.542</td>\n", " <td>0.114</td>\n", " <td>22.235</td>\n", " <td>0.000</td>\n", " <td>0.351</td>\n", " <td>7.235</td>\n", " <td>0.000</td>\n", " </tr>\n", " <tr>\n", " <th>First Class == False, (Swissmetro)</th>\n", " <td>0.565</td>\n", " <td>0.077</td>\n", " <td>7.305</td>\n", " <td>0.000</td>\n", " <td>0.078</td>\n", " <td>7.228</td>\n", " <td>0.000</td>\n", " </tr>\n", " <tr>\n", " <th>Number of Luggage Pieces == 1, (Car)</th>\n", " <td>0.423</td>\n", " <td>0.067</td>\n", " <td>6.270</td>\n", " <td>0.000</td>\n", " <td>0.156</td>\n", " <td>2.706</td>\n", " <td>0.007</td>\n", " </tr>\n", " <tr>\n", " <th>Number of Luggage Pieces &gt; 1, (Car)</th>\n", " <td>1.414</td>\n", " <td>0.259</td>\n", " <td>5.461</td>\n", " <td>0.000</td>\n", " <td>0.494</td>\n", " <td>2.864</td>\n", " <td>0.004</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " parameters std_err \\\n", "ASC Train -1.293 0.146 \n", "ASC Swissmetro -0.503 0.116 \n", "Travel Time, units:hrs (Train and Swissmetro) -0.699 0.042 \n", "Travel Time, units:hrs (Car) -0.723 0.047 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -0.562 0.094 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -0.282 0.045 \n", "Travel Cost, units: 0.01 CHF (Car) -0.514 0.104 \n", "Headway, units:hrs, (Train) -0.314 0.062 \n", "Headway, units:hrs, (Swissmetro) -0.377 0.196 \n", "Airline Seat Configuration, base=No (Swissmetro) -0.782 0.087 \n", "Surveyed on a Train, base=No, (Train and Swissm... 2.542 0.114 \n", "First Class == False, (Swissmetro) 0.565 0.077 \n", "Number of Luggage Pieces == 1, (Car) 0.423 0.067 \n", "Number of Luggage Pieces > 1, (Car) 1.414 0.259 \n", "\n", " t_stats p_values \\\n", "ASC Train -8.845 0.000 \n", "ASC Swissmetro -4.332 0.000 \n", "Travel Time, units:hrs (Train and Swissmetro) -16.545 0.000 \n", "Travel Time, units:hrs (Car) -15.340 0.000 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -6.002 0.000 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -6.252 0.000 \n", "Travel Cost, units: 0.01 CHF (Car) -4.953 0.000 \n", "Headway, units:hrs, (Train) -5.063 0.000 \n", "Headway, units:hrs, (Swissmetro) -1.925 0.054 \n", "Airline Seat Configuration, base=No (Swissmetro) -8.970 0.000 \n", "Surveyed on a Train, base=No, (Train and Swissm... 22.235 0.000 \n", "First Class == False, (Swissmetro) 7.305 0.000 \n", "Number of Luggage Pieces == 1, (Car) 6.270 0.000 \n", "Number of Luggage Pieces > 1, (Car) 5.461 0.000 \n", "\n", " robust_std_err \\\n", "ASC Train 0.303 \n", "ASC Swissmetro 0.392 \n", "Travel Time, units:hrs (Train and Swissmetro) 0.146 \n", "Travel Time, units:hrs (Car) 0.164 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... 0.129 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... 0.067 \n", "Travel Cost, units: 0.01 CHF (Car) 0.230 \n", "Headway, units:hrs, (Train) 0.061 \n", "Headway, units:hrs, (Swissmetro) 0.207 \n", "Airline Seat Configuration, base=No (Swissmetro) 0.097 \n", "Surveyed on a Train, base=No, (Train and Swissm... 0.351 \n", "First Class == False, (Swissmetro) 0.078 \n", "Number of Luggage Pieces == 1, (Car) 0.156 \n", "Number of Luggage Pieces > 1, (Car) 0.494 \n", "\n", " robust_t_stats \\\n", "ASC Train -4.274 \n", "ASC Swissmetro -1.281 \n", "Travel Time, units:hrs (Train and Swissmetro) -4.772 \n", "Travel Time, units:hrs (Car) -4.398 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -4.359 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... -4.236 \n", "Travel Cost, units: 0.01 CHF (Car) -2.234 \n", "Headway, units:hrs, (Train) -5.137 \n", "Headway, units:hrs, (Swissmetro) -1.827 \n", "Airline Seat Configuration, base=No (Swissmetro) -8.058 \n", "Surveyed on a Train, base=No, (Train and Swissm... 7.235 \n", "First Class == False, (Swissmetro) 7.228 \n", "Number of Luggage Pieces == 1, (Car) 2.706 \n", "Number of Luggage Pieces > 1, (Car) 2.864 \n", "\n", " robust_p_values \n", "ASC Train 0.000 \n", "ASC Swissmetro 0.200 \n", "Travel Time, units:hrs (Train and Swissmetro) 0.000 \n", "Travel Time, units:hrs (Car) 0.000 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... 0.000 \n", "Travel Cost * (Annual Pass == 0), units: 0.01 C... 0.000 \n", "Travel Cost, units: 0.01 CHF (Car) 0.025 \n", "Headway, units:hrs, (Train) 0.000 \n", "Headway, units:hrs, (Swissmetro) 0.068 \n", "Airline Seat Configuration, base=No (Swissmetro) 0.000 \n", "Surveyed on a Train, base=No, (Train and Swissm... 0.000 \n", "First Class == False, (Swissmetro) 0.000 \n", "Number of Luggage Pieces == 1, (Car) 0.007 \n", "Number of Luggage Pieces > 1, (Car) 0.004 " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Look at the parameter estimation results, and round the results for easy viewing\n", "np.round(swissmetro_mnl.summary, 3)" ] } ], "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.12" } }, "nbformat": 4, "nbformat_minor": 0 } <MSG> Updating checkpoints for main pylogit example. <DFF> @@ -496,342 +496,318 @@ " <tbody>\n", " <tr>\n", " <th>custom_id</th>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>4.0</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>4</td>\n", " </tr>\n", " <tr>\n", " <th>mode_id</th>\n", - " <td>1.0</td>\n", - " <td>2.0</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>2.0</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>2.0</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", + " <td>1</td>\n", + " <td>2</td>\n", + " <td>3</td>\n", + " <td>1</td>\n", + " <td>2</td>\n", + " <td>3</td>\n", + " <td>1</td>\n", + " <td>2</td>\n", + " <td>3</td>\n", + " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>CHOICE</th>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", + " <td>0</td>\n", + " <td>1</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>1</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>1</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>GROUP</th>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", " </tr>\n", " <tr>\n", " <th>SURVEY</th>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>SP</th>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>ID</th>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>PURPOSE</th>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>FIRST</th>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>TICKET</th>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>WHO</th>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>LUGGAGE</th>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>AGE</th>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", - " <td>3.0</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", + " <td>3</td>\n", " </tr>\n", " <tr>\n", " <th>MALE</th>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>INCOME</th>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", " </tr>\n", " <tr>\n", " <th>GA</th>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>ORIGIN</th>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", - " <td>2.0</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", + " <td>2</td>\n", " </tr>\n", " <tr>\n", " <th>DEST</th>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", + " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>seat_configuration</th>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", + " <td>0</td>\n", " </tr>\n", " <tr>\n", " <th>travel_time</th>\n", - " <td>112.0</td>\n", - " <td>63.0</td>\n", - " <td>117.0</td>\n", - " <td>103.0</td>\n", - " <td>60.0</td>\n", - " <td>117.0</td>\n", - " <td>130.0</td>\n", - " <td>67.0</td>\n", - " <td>117.0</td>\n", - " <td>103.0</td>\n", + " <td>112</td>\n", + " <td>63</td>\n", + " <td>117</td>\n", + " <td>103</td>\n", + " <td>60</td>\n", + " <td>117</td>\n", + " <td>130</td>\n", + " <td>67</td>\n", + " <td>117</td>\n", + " <td>103</td>\n", " </tr>\n", " <tr>\n", " <th>headway</th>\n", - " <td>120.0</td>\n", - " <td>20.0</td>\n", - " <td>0.0</td>\n", - " <td>30.0</td>\n", - " <td>10.0</td>\n", - " <td>0.0</td>\n", - " <td>60.0</td>\n", - " <td>30.0</td>\n", - " <td>0.0</td>\n", - " <td>30.0</td>\n", + " <td>120</td>\n", + " <td>20</td>\n", + " <td>0</td>\n", + " <td>30</td>\n", + " <td>10</td>\n", + " <td>0</td>\n", + " <td>60</td>\n", + " <td>30</td>\n", + " <td>0</td>\n", + " <td>30</td>\n", " </tr>\n", " <tr>\n", " <th>travel_cost</th>\n", - " <td>48.0</td>\n", - " <td>52.0</td>\n", - " <td>65.0</td>\n", - " <td>48.0</td>\n", - " <td>49.0</td>\n", - " <td>84.0</td>\n", - " <td>48.0</td>\n", - " <td>58.0</td>\n", - " <td>52.0</td>\n", - " <td>40.0</td>\n", + " <td>48</td>\n", + " <td>52</td>\n", + " <td>65</td>\n", + " <td>48</td>\n", + " <td>49</td>\n", + " <td>84</td>\n", + " <td>48</td>\n", + " <td>58</td>\n", + " <td>52</td>\n", + " <td>40</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ - " 0 1 2 3 4 5 6 7 \\\n", - "custom_id 1.0 1.0 1.0 2.0 2.0 2.0 3.0 3.0 \n", - "mode_id 1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 \n", - "CHOICE 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 \n", - "GROUP 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 \n", - "SURVEY 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", - "SP 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", - "ID 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", - "PURPOSE 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", - "FIRST 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", - "TICKET 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", - "WHO 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", - "LUGGAGE 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", - "AGE 3.0 3.0 3.0 3.0 3.0 3.0 3.0 3.0 \n", - "MALE 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", - "INCOME 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 \n", - "GA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", - "ORIGIN 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 \n", - "DEST 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 \n", - "seat_configuration 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", - "travel_time 112.0 63.0 117.0 103.0 60.0 117.0 130.0 67.0 \n", - "headway 120.0 20.0 0.0 30.0 10.0 0.0 60.0 30.0
Updating checkpoints for main pylogit example.