diff --git a/activitysim/abm/models/park_and_ride_lot_choice.py b/activitysim/abm/models/park_and_ride_lot_choice.py index e8e0f66835..0d9af664ce 100644 --- a/activitysim/abm/models/park_and_ride_lot_choice.py +++ b/activitysim/abm/models/park_and_ride_lot_choice.py @@ -252,6 +252,12 @@ def run_park_and_ride_lot_choice( f" {len(choosers.index)} != {len(original_index)}" ) + if estimator: + survey_pnr_zone_id = estimator.get_survey_values( + choosers, "tours", "pnr_zone_id" + ) + choosers = choosers.loc[survey_pnr_zone_id != -1].copy() + trn_accessible_choosers = filter_chooser_to_transit_accessible_destinations( state, choosers, @@ -336,15 +342,27 @@ def run_park_and_ride_lot_choice( if estimator: estimator.write_coefficients(model_settings=model_settings) - estimator.write_coefficients_template(model_settings=model_settings) + # no write_coefficients_template: not needed for this model estimator.write_spec(model_settings) estimator.write_model_settings(model_settings, model_settings_file_name) - # in production, all choosers with a transit accessible destination are selected as choosers - # but in estimation, it would only be those who actually reported a pnr lot - # unclear exactly how to handle this, but for now, we will write all choosers estimator.write_choosers(trn_accessible_choosers) estimator.write_alternatives(pnr_alts) + # same convention as other interaction models: chooser index copied into a column + # AFTER write_choosers so the EDB choosers table doesn't get a duplicate ID column + chooser_id = trn_accessible_choosers.index.name + assert chooser_id is not None, "PNR choosers need a named index for estimation" + assert chooser_id not in trn_accessible_choosers.columns + trn_accessible_choosers = trn_accessible_choosers.copy() + trn_accessible_choosers[chooser_id] = trn_accessible_choosers.index + + estimator.set_alt_id("pnr_zone_id") + estimator.set_chooser_id(chooser_id) + + # estimation expression tables are only keyed by chooser ID when the + # interaction dataframe's index is unnamed + pnr_alts = pnr_alts.rename_axis(None) + choices = interaction_simulate( state, choosers=trn_accessible_choosers, @@ -363,21 +381,22 @@ def run_park_and_ride_lot_choice( ) choices = choices.reindex(choosers.index, fill_value=-1) + has_alternatives = choices.index.isin(trn_accessible_choosers.index) + + if estimator: + edb_choices = choices[has_alternatives] + estimator.write_choices(edb_choices) + estimator.write_override_choices( + estimator.get_survey_values(edb_choices, "tours", "pnr_zone_id") + ) + choices = estimator.get_survey_values(choices, "tours", "pnr_zone_id") + estimator.end_estimation() if original_index is not None: # set the choices index back to the original index choices.index = original_index state.get_rn_generator().drop_channel("pnr_lot_choice") - if estimator: - # careful -- there could be some tours in estimation data that are not transit accessible - # but still reported a pnr location - # warning! untested code! - estimator.write_choices(choices) - choices = estimator.get_survey_values(choices, "tours", "pnr_zone_id") - estimator.write_override_choices(choices) - estimator.end_estimation() - return choices diff --git a/activitysim/examples/example_estimation/notebooks/24_park_and_ride_lot_choice.ipynb b/activitysim/examples/example_estimation/notebooks/24_park_and_ride_lot_choice.ipynb new file mode 100644 index 0000000000..d91f1a956e --- /dev/null +++ b/activitysim/examples/example_estimation/notebooks/24_park_and_ride_lot_choice.ipynb @@ -0,0 +1,2009 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "aa380b96", + "metadata": {}, + "source": [ + "# Estimating Park-and-Ride Lot Choice\n", + "\n", + "This notebook estimates the single-segment park-and-ride lot choice model with Larch. The model is an interaction model, so it uses chooser-alternative expression values from the ActivitySim estimation data bundle.\n", + "\n", + "Run ActivitySim in estimation mode first. The estimation run must include the park-and-ride fixes that preserve `pnr_zone_id` and configure it as the alternative ID." + ] + }, + { + "cell_type": "markdown", + "id": "0fc282d4", + "metadata": {}, + "source": [ + "## Load libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "5b0bb89c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'larch': '6.0.46',\n", + " 'sharrow': '2.16.2',\n", + " 'numpy': '2.2.6',\n", + " 'pandas': '2.3.2',\n", + " 'xarray': '2025.6.1',\n", + " 'numba': '0.62.0',\n", + " 'jax': 'not installed'}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from pathlib import Path\n", + "from types import SimpleNamespace\n", + "\n", + "import larch as lx\n", + "import pandas as pd\n", + "\n", + "from activitysim.estimation.larch.general import (\n", + " apply_coefficients,\n", + " linear_utility_from_spec,\n", + " update_coefficients,\n", + ")\n", + "\n", + "lx.versions()" + ] + }, + { + "cell_type": "markdown", + "id": "b75db7a9", + "metadata": {}, + "source": [ + "## Locate the estimation data bundle\n", + "\n", + "Change `EDB_DIRECTORY` if your ActivitySim output directory is elsewhere." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "068f1c00", + "metadata": {}, + "outputs": [], + "source": [ + "modelname = \"park_and_ride_lot_choice\"\n", + "#EDB_DIRECTORY = Path(\"output-est-mode/estimation_data_bundle/{modelname}/\")\n", + "EDB_DIRECTORY = Path(r\"D:\\stefan\\asim_estimation_pnr\\outputs_current\\estimation_data_bundle\\park_and_ride_lot_choice\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "00ccf73d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Using coefficient file: park_and_ride_lot_choice_coefficients.csv\n" + ] + }, + { + "data": { + "text/plain": [ + "( value constrain\n", + " coefficient_name \n", + " coef_zero 0.000000 T\n", + " coef_unavailable -999.000000 F\n", + " coef_ivt_auto -0.077806 F\n", + " coef_ivt_transit -0.048312 F\n", + " coef_auto_op_costs 0.000000 F,\n", + " Label Description \\\n", + " 4 util_drive_time round trip drive time from origin to lot \n", + " 5 util_drive_tolls toll costs \n", + " 6 util_first_wait first wait time \n", + " 7 util_xfer_wait transfer wait time \n", + " 8 util_total_wait total wait time \n", + " \n", + " Expression coefficient \n", + " 4 @_d_pnr_time_skims_out + _d_pnr_time_skims_inb coef_ivt_auto \n", + " 5 @_d_pnr_cost_skims_out + _d_pnr_cost_skims_inb coef_toll_auto \n", + " 6 @(ldt_skims['iwtwpnr'] + dlt_skims['iwtwpnr']) coef_wait_transit \n", + " 7 @((ldt_skims['twtwpnr'] + dlt_skims['twtwpnr']... coef_xwait_transit \n", + " 8 @(ldt_skims['twtwpnr'] + dlt_skims['twtwpnr']) coef_wait_transit ,\n", + " zone_id pnr_zone_id tour_id util_drive_time util_drive_tolls \\\n", + " 0 66235 66235 14814610 74.881622 0.0 \n", + " 1 66235 66235 14612890 50.089542 0.0 \n", + " 2 66235 66235 13362800 39.652969 0.0 \n", + " 3 66235 66235 12625210 75.346634 0.0 \n", + " 4 66235 66235 11764210 56.118599 0.0 \n", + " \n", + " util_first_wait util_xfer_wait util_total_wait util_walk_time \\\n", + " 0 15.713741 12.450089 28.163830 14.494038 \n", + " 1 21.000000 14.318184 35.318184 96.828720 \n", + " 2 17.753656 18.809252 36.562908 27.354671 \n", + " 3 21.000000 16.810909 37.810909 11.533979 \n", + " 4 21.000000 26.178574 47.178574 12.995800 \n", + " \n", + " util_ivtt util_transfer_penalty util_log_lot_capacity \\\n", + " 0 35.463264 2.000000 5.968708 \n", + " 1 64.872787 2.545455 5.968708 \n", + " 2 54.604248 2.382142 5.968708 \n", + " 3 104.680817 2.525692 5.968708 \n", + " 4 92.420982 4.000000 5.968708 \n", + " \n", + " util_percent_drive \n", + " 0 0.678614 \n", + " 1 0.435704 \n", + " 2 0.420689 \n", + " 3 0.418529 \n", + " 4 0.377802 ,\n", + " tour_id model_choice override_choice person_id tour_type \\\n", + " 0 214174 66287 66287.0 5223 school \n", + " 1 694210 66298 66287.0 16931 work \n", + " 2 1009948 66287 66283.0 24632 social \n", + " 3 1604820 66305 66338.0 39141 work \n", + " 4 1899200 66236 66260.0 46321 work \n", + " \n", + " tour_type_count tour_type_num tour_num tour_count tour_category ... \\\n", + " 0 1 1 1 1 mandatory ... \n", + " 1 1 1 1 1 mandatory ... \n", + " 2 1 1 1 1 non_mandatory ... \n", + " 3 1 1 1 1 mandatory ... \n", + " 4 1 1 1 1 mandatory ... \n", + " \n", + " cost_sensitivity sov_auto_op_cost coef_ivt coef_inc_adj_cost \\\n", + " 0 500.000000 32.5 -0.017 -0.262 \n", + " 1 63.095734 32.5 -0.016 -0.625 \n", + " 2 132.287566 32.5 -0.017 -0.262 \n", + " 3 923.006654 32.5 -0.016 -0.625 \n", + " 4 1399.016476 32.5 -0.016 -0.625 \n", + " \n", + " income_exponent c_cost time_factor c_ivt vot_d_pnr vot_bin_d_pnr \n", + " 0 0.5 -0.000524 0.480450 -0.008168 9.352262 1 \n", + " 1 0.6 -0.009906 1.671230 -0.026740 1.619674 1 \n", + " 2 0.5 -0.001981 0.534573 -0.009088 2.753117 1 \n", + " 3 0.6 -0.000677 0.942869 -0.015086 13.367421 2 \n", + " 4 0.6 -0.000447 0.537450 -0.008599 11.549205 2 \n", + " \n", + " [5 rows x 202 columns])" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def read_edb_file(filename, **kwargs):\n", + " path = EDB_DIRECTORY / filename\n", + " parquet_path = path.with_suffix(\".parquet\")\n", + " if parquet_path.exists():\n", + " return pd.read_parquet(parquet_path, **kwargs)\n", + " if not path.exists():\n", + " raise FileNotFoundError(\n", + " f\"Missing {path.name}. Re-run ActivitySim estimation after setting \"\n", + " f\"the park-and-ride chooser ID, then coalesce the interaction EDB.\"\n", + " )\n", + " return pd.read_csv(path, **kwargs)\n", + "\n", + "coefficient_candidates = [\n", + " f\"{modelname}_coefficients.csv\",\n", + " f\"{modelname}_{modelname}_coeffs.csv\",\n", + " f\"{modelname}_coeffs.csv\",\n", + "]\n", + "coefficient_file = next(\n", + " (filename for filename in coefficient_candidates if (EDB_DIRECTORY / filename).exists()),\n", + " None,\n", + ")\n", + "if coefficient_file is None:\n", + " raise FileNotFoundError(\n", + " f\"Could not find PNR coefficients in {EDB_DIRECTORY}. \"\n", + " f\"Expected one of: {coefficient_candidates}\"\n", + " )\n", + "\n", + "coefficients = read_edb_file(coefficient_file, index_col=\"coefficient_name\")\n", + "spec = read_edb_file(f\"{modelname}_SPEC.csv\", comment=\"#\")\n", + "alternatives = read_edb_file(f\"{modelname}_alternatives_combined.csv\")\n", + "choosers = read_edb_file(f\"{modelname}_choosers_combined.csv\")\n", + "\n", + "if \"pnr_zone_id\" not in alternatives.columns:\n", + " raise KeyError(f\"Expected 'pnr_zone_id' in alternatives: {alternatives.columns.tolist()}\")\n", + "chooser_id_column = choosers.columns[0]\n", + "if chooser_id_column not in alternatives.columns:\n", + " raise ValueError(\n", + " f\"The alternatives EDB is missing chooser ID {chooser_id_column!r}. \"\n", + " \"Re-run estimation after setting estimator.set_chooser_id(...) in the \"\n", + " \"park-and-ride model.\"\n", + " )\n", + "\n", + "spec = spec.loc[spec.Expression.notna()].copy()\n", + "spec = spec.loc[~spec.Expression.str.startswith(\"_\")].copy()\n", + "print(f\"Using coefficient file: {coefficient_file}\")\n", + "coefficients.head(), spec.head(), alternatives.head(), choosers.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "bb13b53a", + "metadata": {}, + "outputs": [], + "source": [ + "# Optional: exclude survey tours with a ~$17.90 toll on the home-to-lot leg (likely ferry); the toll is not modeled\n", + "# EXCLUDED_TOUR_IDS = [10431751, 9927843]\n", + "# alternatives = alternatives.loc[~alternatives[chooser_id_column].isin(EXCLUDED_TOUR_IDS)].copy()\n", + "# choosers = choosers.loc[~choosers[chooser_id_column].isin(EXCLUDED_TOUR_IDS)].copy()" + ] + }, + { + "cell_type": "markdown", + "id": "3dbc8ad2", + "metadata": {}, + "source": [ + "## Build the Larch interaction model\n", + "\n", + "The first two columns of `alternatives_combined` identify the chooser and alternative. The chooser table contains the observed choice written by ActivitySim. PNR uses `pnr_zone_id` as the alternative ID." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "aaa06ea2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CA index: ['tour_id', 'pnr_zone_id'], unique=True, rows=5733\n", + "CO index: tour_id, unique=True, rows=39\n" + ] + }, + { + "data": { + "text/html": [ + "
keyvalue
ca
['util_drive_time',\n",
+       " 'util_drive_tolls',\n",
+       " 'util_first_wait',\n",
+       " 'util_ivtt',\n",
+       " 'util_log_lot_capacity',\n",
+       " 'util_percent_drive',\n",
+       " 'util_total_wait',\n",
+       " 'util_transfer_penalty',\n",
+       " 'util_walk_time',\n",
+       " 'util_xfer_wait']
choice_co_code'override_choice'
avail_anyTrue
" + ], + "text/plain": [ + "┣ ca: ['util_drive_time',\n", + "┃ 'util_drive_tolls',\n", + "┃ 'util_first_wait',\n", + "┃ 'util_ivtt',\n", + "┃ 'util_log_lot_capacity',\n", + "┃ 'util_percent_drive',\n", + "┃ 'util_total_wait',\n", + "┃ 'util_transfer_penalty',\n", + "┃ 'util_walk_time',\n", + "┃ 'util_xfer_wait']\n", + "┣ choice_co_code: 'override_choice'\n", + "┣ avail_any: True" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "########Build the interaction model\n", + "alternative_id_column = \"pnr_zone_id\"\n", + "\n", + "if alternative_id_column not in alternatives.columns:\n", + " raise KeyError(f\"Expected {alternative_id_column!r} in alternatives: {alternatives.columns.tolist()}\")\n", + "\n", + "key_columns = [chooser_id_column, alternative_id_column]\n", + "duplicate_count = int(alternatives.duplicated(key_columns).sum())\n", + "if duplicate_count:\n", + " print(f\"Removing {duplicate_count} duplicate chooser-alternative rows from the EDB\")\n", + " alternatives = alternatives.drop_duplicates(key_columns, keep=\"last\").copy()\n", + "\n", + "x_ca = alternatives.set_index(key_columns)\n", + "choosers = choosers.drop_duplicates(chooser_id_column, keep=\"last\").copy()\n", + "x_co = choosers.loc[choosers[chooser_id_column].isin(alternatives[chooser_id_column])].set_index(chooser_id_column)\n", + "\n", + "print(f\"CA index: {x_ca.index.names}, unique={x_ca.index.is_unique}, rows={len(x_ca)}\")\n", + "print(f\"CO index: {x_co.index.name}, unique={x_co.index.is_unique}, rows={len(x_co)}\")\n", + "\n", + "choice_candidates = [\"override_choice\", \"model_choice\", \"choice\", \"pnr_zone_id\"]\n", + "choice_column = next((c for c in choice_candidates if c in x_co.columns), None)\n", + "if choice_column is None:\n", + " raise KeyError(f\"Could not find an observed choice column in {x_co.columns.tolist()}\")\n", + "\n", + "# Keep constant chooser-alternative variables two-dimensional for Larch.\n", + "d_ca = lx.Dataset.construct.from_idca(x_ca, crack=False)\n", + "d_co = lx.Dataset.construct.from_idco(x_co)\n", + "datatree = d_ca.merge(d_co)\n", + "\n", + "model = lx.Model(datatree=datatree, compute_engine=\"numba\")\n", + "alt_codes = datatree.dc.altids()\n", + "root_id = -1 if 0 in alt_codes else 0\n", + "model.initialize_graph(alternative_codes=alt_codes, root_id=root_id)\n", + "\n", + "model.utility_ca = linear_utility_from_spec(\n", + " spec,\n", + " x_col=\"Label\",\n", + " p_col=\"coefficient\",\n", + " ignore_x=(\"#\",),\n", + " x_validator=set(x_ca.columns),\n", + " expr_col=\"Expression\",\n", + ")\n", + "apply_coefficients(coefficients, model)\n", + "model.choice_co_code = choice_column\n", + "model.availability_any = True\n", + "model.set_cap(50)\n", + "\n", + "model.required_data()" + ] + }, + { + "cell_type": "markdown", + "id": "353a1429", + "metadata": {}, + "source": [ + "## Review and diagnose the model" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "69b71ce3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
<empty>
" + ], + "text/plain": [ + "dictx()" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model, problems = model.doctor()\n", + "problems" + ] + }, + { + "cell_type": "markdown", + "id": "775a2667", + "metadata": {}, + "source": [ + "## Estimate" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "6dca5930", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "

Iteration 070 [Optimization terminated successfully]

" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "

Best LL = -85.95625856645239

" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
valuebestinitvalueminimummaximumnullvalueholdfast
param_name
coef_ivt_auto-0.064196-0.064196-0.077806-50.050.00.00
coef_ivt_transit-0.069902-0.069902-0.048312-50.050.00.00
coef_lot_capacity0.4737610.4737610.662689-50.050.00.00
coef_percent_drive-5.823242-5.8232420.000000-50.050.00.00
coef_toll_auto0.2210470.2210470.000000-50.050.00.00
coef_wait_transit-0.017792-0.017792-0.044691-50.050.00.00
coef_walk_transit-0.043890-0.043890-0.112051-50.050.00.00
coef_xfer_transit-0.205820-0.2058200.000000-50.050.00.00
coef_xwait_transit-0.005215-0.0052150.000000-50.050.00.00
\n", + "
" + ], + "text/plain": [ + " value best initvalue minimum maximum \\\n", + "param_name \n", + "coef_ivt_auto -0.064196 -0.064196 -0.077806 -50.0 50.0 \n", + "coef_ivt_transit -0.069902 -0.069902 -0.048312 -50.0 50.0 \n", + "coef_lot_capacity 0.473761 0.473761 0.662689 -50.0 50.0 \n", + "coef_percent_drive -5.823242 -5.823242 0.000000 -50.0 50.0 \n", + "coef_toll_auto 0.221047 0.221047 0.000000 -50.0 50.0 \n", + "coef_wait_transit -0.017792 -0.017792 -0.044691 -50.0 50.0 \n", + "coef_walk_transit -0.043890 -0.043890 -0.112051 -50.0 50.0 \n", + "coef_xfer_transit -0.205820 -0.205820 0.000000 -50.0 50.0 \n", + "coef_xwait_transit -0.005215 -0.005215 0.000000 -50.0 50.0 \n", + "\n", + " nullvalue holdfast \n", + "param_name \n", + "coef_ivt_auto 0.0 0 \n", + "coef_ivt_transit 0.0 0 \n", + "coef_lot_capacity 0.0 0 \n", + "coef_percent_drive 0.0 0 \n", + "coef_toll_auto 0.0 0 \n", + "coef_wait_transit 0.0 0 \n", + "coef_walk_transit 0.0 0 \n", + "coef_xfer_transit 0.0 0 \n", + "coef_xwait_transit 0.0 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
keyvalue
loglikenp.float64(-85.95625856645239)
x\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
0
coef_ivt_auto-0.064196
coef_ivt_transit-0.069902
coef_lot_capacity0.473761
coef_percent_drive-5.823242
coef_toll_auto0.221047
coef_wait_transit-0.017792
coef_walk_transit-0.043890
coef_xfer_transit-0.205820
coef_xwait_transit-0.005215
tolerancenp.float64(7.46270403264644e-06)
steps
array([1.        , 1.        , 0.5       , 0.5       , 0.5       ,\n",
+       "       0.5       , 0.25      , 0.1125    , 0.3725    , 0.1735    ,\n",
+       "       0.14085   , 0.41974   , 0.243818  , 0.1350408 , 0.44517952,\n",
+       "       0.13846283, 0.27644823, 0.12389494, 0.44761053, 0.1431596 ,\n",
+       "       0.22591523, 0.24340571, 0.2367972 , 0.12968883, 0.39158663,\n",
+       "       0.24547872, 0.24939142, 0.12529428, 0.45657595, 0.1468327 ,\n",
+       "       0.24471461, 0.24456179, 0.24359586, 0.13362809, 0.40533322,\n",
+       "       0.25436672, 0.25629714, 0.1293221 , 0.47157891, 0.15168981,\n",
+       "       0.25265093, 0.25230778, 0.25150991, 0.13797373, 0.41845286,\n",
+       "       0.26257904, 0.13228233, 0.48111915, 0.14324071, 0.57506964,\n",
+       "       0.15942909, 0.29822819, 0.16570868, 0.26833526, 0.29335417,\n",
+       "       0.23701108, 0.12626374, 0.43626917, 0.27224668, 0.13651448,\n",
+       "       0.48332206, 0.14546161, 0.5895256 , 0.16270704, 0.30350616,\n",
+       "       0.16845225, 0.27393053, 0.14981216, 0.42336326, 0.13190644])
message'Optimization terminated successfully'
elapsed_time0:00:01.152258
method'BHHH'
n_cases39
iteration_number70
" + ], + "text/plain": [ + "┣ loglike: np.float64(-85.95625856645239)\n", + "┣ x: coef_ivt_auto -0.064196\n", + "┃ coef_ivt_transit -0.069902\n", + "┃ coef_lot_capacity 0.473761\n", + "┃ coef_percent_drive -5.823242\n", + "┃ coef_toll_auto 0.221047\n", + "┃ coef_wait_transit -0.017792\n", + "┃ coef_walk_transit -0.043890\n", + "┃ coef_xfer_transit -0.205820\n", + "┃ coef_xwait_transit -0.005215\n", + "┃ dtype: float64\n", + "┣ tolerance: np.float64(7.46270403264644e-06)\n", + "┣ steps: array([1. , 1. , 0.5 , 0.5 , 0.5 ,\n", + "┃ 0.5 , 0.25 , 0.1125 , 0.3725 , 0.1735 ,\n", + "┃ 0.14085 , 0.41974 , 0.243818 , 0.1350408 , 0.44517952,\n", + "┃ 0.13846283, 0.27644823, 0.12389494, 0.44761053, 0.1431596 ,\n", + "┃ 0.22591523, 0.24340571, 0.2367972 , 0.12968883, 0.39158663,\n", + "┃ 0.24547872, 0.24939142, 0.12529428, 0.45657595, 0.1468327 ,\n", + "┃ 0.24471461, 0.24456179, 0.24359586, 0.13362809, 0.40533322,\n", + "┃ 0.25436672, 0.25629714, 0.1293221 , 0.47157891, 0.15168981,\n", + "┃ 0.25265093, 0.25230778, 0.25150991, 0.13797373, 0.41845286,\n", + "┃ 0.26257904, 0.13228233, 0.48111915, 0.14324071, 0.57506964,\n", + "┃ 0.15942909, 0.29822819, 0.16570868, 0.26833526, 0.29335417,\n", + "┃ 0.23701108, 0.12626374, 0.43626917, 0.27224668, 0.13651448,\n", + "┃ 0.48332206, 0.14546161, 0.5895256 , 0.16270704, 0.30350616,\n", + "┃ 0.16845225, 0.27393053, 0.14981216, 0.42336326, 0.13190644])\n", + "┣ message: 'Optimization terminated successfully'\n", + "┣ elapsed_time: datetime.timedelta(seconds=1, microseconds=152258)\n", + "┣ method: 'BHHH'\n", + "┣ n_cases: 39\n", + "┣ iteration_number: 70" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.estimate(method=\"BHHH\", options={\"maxiter\": 1000})" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "be2c068f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
StatisticAggregatePer Case
Number of Cases39
Log Likelihood at Convergence-85.96-2.20
Log Likelihood at Null Parameters-194.63-4.99
Rho Squared w.r.t. Null Parameters0.558
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.parameter_summary()\n", + "model.estimation_statistics()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f6cfc06", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "ba7d6d28", + "metadata": {}, + "source": [ + "## Write estimation results" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "3a66df6b", + "metadata": {}, + "outputs": [], + "source": [ + "result_dir = EDB_DIRECTORY / \"estimated\"\n", + "data = SimpleNamespace(edb_directory=EDB_DIRECTORY, coefficients=coefficients)\n", + "\n", + "update_coefficients(\n", + " model,\n", + " data,\n", + " result_dir,\n", + " output_file=f\"{modelname}_coefficients.csv\",\n", + ")\n", + "\n", + "model.to_xlsx(\n", + " result_dir / f\"{modelname}_model_estimation.xlsx\",\n", + " data_statistics=False,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "be5ddd94", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ValueStd Errt StatSignifNull Value
Parameter     
coef_ivt_auto-0.0642 0.0157-4.10*** 0.00
coef_ivt_transit-0.0699 0.0167-4.17*** 0.00
coef_lot_capacity 0.474 0.182 2.60** 0.00
coef_percent_drive-5.82 2.37-2.46* 0.00
coef_toll_auto 0.221 0.0839 2.63** 0.00
coef_wait_transit-0.0178 0.0125-1.42 0.00
coef_walk_transit-0.0439 0.0202-2.17* 0.00
coef_xfer_transit-0.206 0.355-0.58 0.00
coef_xwait_transit-0.00522 0.0291-0.18 0.00
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.parameter_summary()" + ] + }, + { + "cell_type": "markdown", + "id": "484b9444", + "metadata": {}, + "source": [] + }, + { + "cell_type": "markdown", + "id": "13cd60ff", + "metadata": {}, + "source": [ + "## Next steps\n", + "\n", + "Review the revised coefficient file, then copy `park_and_ride_lot_choice_coefficients.csv` into the active configuration directory before running ActivitySim in simulation mode." + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "26f1079d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
coefficient_namevalueconstrain
0coef_zero0.000000T
1coef_unavailable-999.000000F
2coef_ivt_auto-0.064196F
3coef_ivt_transit-0.069902F
4coef_auto_op_costs0.000000F
5coef_walk_transit-0.043890F
6coef_wait_transit-0.017792F
7coef_xfer_transit-0.205820F
8coef_xwait_transit-0.005215F
9coef_small_lot0.000000F
10coef_medium_lot0.000000F
11coef_detour_dist0.000000F
12coef_percent_drive-5.823242F
13coef_lot_capacity0.473761F
14coef_toll_auto0.221047F
\n", + "
" + ], + "text/plain": [ + " coefficient_name value constrain\n", + "0 coef_zero 0.000000 T\n", + "1 coef_unavailable -999.000000 F\n", + "2 coef_ivt_auto -0.064196 F\n", + "3 coef_ivt_transit -0.069902 F\n", + "4 coef_auto_op_costs 0.000000 F\n", + "5 coef_walk_transit -0.043890 F\n", + "6 coef_wait_transit -0.017792 F\n", + "7 coef_xfer_transit -0.205820 F\n", + "8 coef_xwait_transit -0.005215 F\n", + "9 coef_small_lot 0.000000 F\n", + "10 coef_medium_lot 0.000000 F\n", + "11 coef_detour_dist 0.000000 F\n", + "12 coef_percent_drive -5.823242 F\n", + "13 coef_lot_capacity 0.473761 F\n", + "14 coef_toll_auto 0.221047 F" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pd.read_csv(result_dir / f\"{modelname}_coefficients.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "cc467ed6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Chosen Alt MeanAll Alts MeanDifference
Variable
util_drive_time35.137123112.517128-77.380005
util_drive_tolls0.4576321.963738-1.506105
util_first_wait21.11221525.060415-3.948200
util_xfer_wait11.28640034.743252-23.456852
util_total_wait32.39861359.803665-27.405052
util_walk_time25.22151941.669800-16.448280
util_ivtt56.971474120.209511-63.238037
util_transfer_penalty1.0257272.760425-1.734697
util_log_lot_capacity6.1967385.1871291.009609
util_percent_drive0.3825480.469714-0.087166
\n", + "
" + ], + "text/plain": [ + " Chosen Alt Mean All Alts Mean Difference\n", + "Variable \n", + "util_drive_time 35.137123 112.517128 -77.380005\n", + "util_drive_tolls 0.457632 1.963738 -1.506105\n", + "util_first_wait 21.112215 25.060415 -3.948200\n", + "util_xfer_wait 11.286400 34.743252 -23.456852\n", + "util_total_wait 32.398613 59.803665 -27.405052\n", + "util_walk_time 25.221519 41.669800 -16.448280\n", + "util_ivtt 56.971474 120.209511 -63.238037\n", + "util_transfer_penalty 1.025727 2.760425 -1.734697\n", + "util_log_lot_capacity 6.196738 5.187129 1.009609\n", + "util_percent_drive 0.382548 0.469714 -0.087166" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Compare mean predictor values for the chosen alternative vs. all alternatives\n", + "predictor_cols = [col for col in dict.fromkeys(spec[\"Label\"]) if col in x_ca.columns]\n", + "\n", + "chosen_by_chooser = x_co[choice_column].to_dict()\n", + "alt_ids = x_ca.index.get_level_values(alternative_id_column)\n", + "chooser_ids = x_ca.index.get_level_values(chooser_id_column)\n", + "is_chosen = alt_ids == chooser_ids.map(chosen_by_chooser)\n", + "\n", + "comparison = pd.DataFrame(\n", + " {\n", + " \"Chosen Alt Mean\": x_ca.loc[is_chosen, predictor_cols].mean(),\n", + " \"All Alts Mean\": x_ca[predictor_cols].mean(),\n", + " }\n", + ")\n", + "comparison[\"Difference\"] = comparison[\"Chosen Alt Mean\"] - comparison[\"All Alts Mean\"]\n", + "comparison.index.name = \"Variable\"\n", + "comparison" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "be8514ac", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
util_drive_timeutil_drive_tollsutil_first_waitutil_xfer_waitutil_total_waitutil_walk_timeutil_ivttutil_transfer_penaltyutil_log_lot_capacityutil_percent_drive
tour_idpnr_zone_id
92505006623618.4590890.00000031.00840219.62206850.63047032.576805111.6475371.7142867.7336840.141877
41837616623616.6614670.00000012.9193550.00000012.91935513.617260116.2808690.0000007.7336840.125329
48721106624165.9515530.00000011.8347580.00000011.8347584.9893944.9948120.0000006.9047510.929597
38385006624262.1150250.00000026.25000018.46034644.71034619.76447591.4646991.3333336.4567700.404448
112513006624833.6737400.00000026.7857130.00000026.78571311.51956039.7726820.0000005.7807440.458480
18992006626022.3255860.00000022.0000000.00000022.00000019.93128039.9177130.0000005.2781150.358683
61258906626813.6768510.00000014.8677243.95604418.82376922.27482085.1188200.8571436.0038870.138436
146128906627629.4290620.00000014.9704140.00000014.97041479.7499629.9898680.0000006.1047930.746572
31538006627629.0202290.00000018.60061830.66173449.26235215.98037975.5919883.4551096.1047930.277408
40020576628113.0056010.00000035.00000095.000000130.00000028.56836395.4672472.0000007.3138870.119897
77999616628320.8226930.0000007.0083663.75000010.75836718.66214444.3049551.0000007.3870900.319721
29578206628322.7787900.00000035.15251533.73077068.88328629.06554885.7426763.0000007.3870900.209901
10099486628323.9322300.0000009.4139809.73240419.14638322.06671057.6207202.0000007.3870900.293456
70373616628532.3382950.0000005.0357470.0000005.03574713.30697820.9386250.0000003.9512440.606985
59044876628564.5337220.00000033.00000020.43750053.4375008.51596160.0328602.0000003.9512440.518066
6942106628728.0423660.00000020.09090812.23684332.32775110.93482038.3353042.0000006.6669570.422467
2141746628711.1126510.00000012.5000000.00000012.50000014.79068029.1417770.0000006.6669570.276060
90368726628719.3477690.00000011.00000010.25000021.25000011.16944061.9364052.0000006.6669570.238026
117642106628935.7300190.00000017.0021110.00000017.00211111.5504596.5521250.0000006.1548580.845038
113870516628968.3216250.00000014.77529324.66666639.44195972.30638138.4869921.8546366.1548580.639664
11612100662915.7333730.00000082.5000000.00000082.50000040.17838337.9764250.0000005.9348940.131169
30795846630041.9797020.0000009.6328740.0000009.63287437.4437527.9967210.0000005.3981630.839990
133628006630328.2645720.00000019.0000000.00000019.00000024.97772030.5288700.0000004.0253520.480744
68938206630330.7290310.00000017.2826080.00000017.28260837.51629322.6041150.0000004.0253520.576171
5330874663047.6072430.00000011.50000014.50000026.00000027.07579088.8222812.0000006.0210230.078889
5979517663047.4668370.00000018.0697670.00000018.06976720.48982030.5326750.0000006.0210230.196498
36999616630533.9578400.00000011.5909090.00000011.59090911.87053324.4256290.0000007.2758650.581635
21419206630513.5087360.0000008.0000000.0000008.00000015.62184035.2300000.0000007.2758650.277166
148146106630617.0389290.0000007.3333335.18324612.51657938.48493253.3959501.0000006.2166060.241910
89192206631359.6034550.00000016.3157908.26953724.58532736.93319745.6828541.0350885.5606820.566108
992784366313209.95127917.84765615.31579047.60526362.92105151.857876111.6820373.7894745.5606820.652766
96568106631515.5678670.00000020.2826080.00000020.28260811.59906062.5255660.0000007.5480290.199349
110868906633421.8370250.00000046.5000000.00000046.50000045.19903970.0000000.0000005.2364420.237780
61066096633452.6945530.00000036.00000038.00000074.00000029.649759127.7894742.0000005.2364420.291962
1604820663388.0403060.0000007.83333311.71428619.54761911.65601756.2813952.0000005.3132060.125001
103287826635291.6060790.00000015.42857219.82142835.25000029.09987470.3625182.9642866.9275580.565579
126252106635710.5667380.00000010.07486612.57142922.64629612.82751846.9823612.0000006.9087550.183613
104317516636341.3225330.00000082.5000000.00000082.50000019.86190880.0000000.0000006.3403590.340601
72083286638041.5932770.0000009.0000000.0000009.00000019.954599105.7300030.0000007.0570370.282327
\n", + "
" + ], + "text/plain": [ + " util_drive_time util_drive_tolls util_first_wait \\\n", + "tour_id pnr_zone_id \n", + "9250500 66236 18.459089 0.000000 31.008402 \n", + "4183761 66236 16.661467 0.000000 12.919355 \n", + "4872110 66241 65.951553 0.000000 11.834758 \n", + "3838500 66242 62.115025 0.000000 26.250000 \n", + "11251300 66248 33.673740 0.000000 26.785713 \n", + "1899200 66260 22.325586 0.000000 22.000000 \n", + "6125890 66268 13.676851 0.000000 14.867724 \n", + "14612890 66276 29.429062 0.000000 14.970414 \n", + "3153800 66276 29.020229 0.000000 18.600618 \n", + "4002057 66281 13.005601 0.000000 35.000000 \n", + "7799961 66283 20.822693 0.000000 7.008366 \n", + "2957820 66283 22.778790 0.000000 35.152515 \n", + "1009948 66283 23.932230 0.000000 9.413980 \n", + "7037361 66285 32.338295 0.000000 5.035747 \n", + "5904487 66285 64.533722 0.000000 33.000000 \n", + "694210 66287 28.042366 0.000000 20.090908 \n", + "214174 66287 11.112651 0.000000 12.500000 \n", + "9036872 66287 19.347769 0.000000 11.000000 \n", + "11764210 66289 35.730019 0.000000 17.002111 \n", + "11387051 66289 68.321625 0.000000 14.775293 \n", + "11612100 66291 5.733373 0.000000 82.500000 \n", + "3079584 66300 41.979702 0.000000 9.632874 \n", + "13362800 66303 28.264572 0.000000 19.000000 \n", + "6893820 66303 30.729031 0.000000 17.282608 \n", + "5330874 66304 7.607243 0.000000 11.500000 \n", + "5979517 66304 7.466837 0.000000 18.069767 \n", + "3699961 66305 33.957840 0.000000 11.590909 \n", + "2141920 66305 13.508736 0.000000 8.000000 \n", + "14814610 66306 17.038929 0.000000 7.333333 \n", + "8919220 66313 59.603455 0.000000 16.315790 \n", + "9927843 66313 209.951279 17.847656 15.315790 \n", + "9656810 66315 15.567867 0.000000 20.282608 \n", + "11086890 66334 21.837025 0.000000 46.500000 \n", + "6106609 66334 52.694553 0.000000 36.000000 \n", + "1604820 66338 8.040306 0.000000 7.833333 \n", + "10328782 66352 91.606079 0.000000 15.428572 \n", + "12625210 66357 10.566738 0.000000 10.074866 \n", + "10431751 66363 41.322533 0.000000 82.500000 \n", + "7208328 66380 41.593277 0.000000 9.000000 \n", + "\n", + " util_xfer_wait util_total_wait util_walk_time \\\n", + "tour_id pnr_zone_id \n", + "9250500 66236 19.622068 50.630470 32.576805 \n", + "4183761 66236 0.000000 12.919355 13.617260 \n", + "4872110 66241 0.000000 11.834758 4.989394 \n", + "3838500 66242 18.460346 44.710346 19.764475 \n", + "11251300 66248 0.000000 26.785713 11.519560 \n", + "1899200 66260 0.000000 22.000000 19.931280 \n", + "6125890 66268 3.956044 18.823769 22.274820 \n", + "14612890 66276 0.000000 14.970414 79.749962 \n", + "3153800 66276 30.661734 49.262352 15.980379 \n", + "4002057 66281 95.000000 130.000000 28.568363 \n", + "7799961 66283 3.750000 10.758367 18.662144 \n", + "2957820 66283 33.730770 68.883286 29.065548 \n", + "1009948 66283 9.732404 19.146383 22.066710 \n", + "7037361 66285 0.000000 5.035747 13.306978 \n", + "5904487 66285 20.437500 53.437500 8.515961 \n", + "694210 66287 12.236843 32.327751 10.934820 \n", + "214174 66287 0.000000 12.500000 14.790680 \n", + "9036872 66287 10.250000 21.250000 11.169440 \n", + "11764210 66289 0.000000 17.002111 11.550459 \n", + "11387051 66289 24.666666 39.441959 72.306381 \n", + "11612100 66291 0.000000 82.500000 40.178383 \n", + "3079584 66300 0.000000 9.632874 37.443752 \n", + "13362800 66303 0.000000 19.000000 24.977720 \n", + "6893820 66303 0.000000 17.282608 37.516293 \n", + "5330874 66304 14.500000 26.000000 27.075790 \n", + "5979517 66304 0.000000 18.069767 20.489820 \n", + "3699961 66305 0.000000 11.590909 11.870533 \n", + "2141920 66305 0.000000 8.000000 15.621840 \n", + "14814610 66306 5.183246 12.516579 38.484932 \n", + "8919220 66313 8.269537 24.585327 36.933197 \n", + "9927843 66313 47.605263 62.921051 51.857876 \n", + "9656810 66315 0.000000 20.282608 11.599060 \n", + "11086890 66334 0.000000 46.500000 45.199039 \n", + "6106609 66334 38.000000 74.000000 29.649759 \n", + "1604820 66338 11.714286 19.547619 11.656017 \n", + "10328782 66352 19.821428 35.250000 29.099874 \n", + "12625210 66357 12.571429 22.646296 12.827518 \n", + "10431751 66363 0.000000 82.500000 19.861908 \n", + "7208328 66380 0.000000 9.000000 19.954599 \n", + "\n", + " util_ivtt util_transfer_penalty \\\n", + "tour_id pnr_zone_id \n", + "9250500 66236 111.647537 1.714286 \n", + "4183761 66236 116.280869 0.000000 \n", + "4872110 66241 4.994812 0.000000 \n", + "3838500 66242 91.464699 1.333333 \n", + "11251300 66248 39.772682 0.000000 \n", + "1899200 66260 39.917713 0.000000 \n", + "6125890 66268 85.118820 0.857143 \n", + "14612890 66276 9.989868 0.000000 \n", + "3153800 66276 75.591988 3.455109 \n", + "4002057 66281 95.467247 2.000000 \n", + "7799961 66283 44.304955 1.000000 \n", + "2957820 66283 85.742676 3.000000 \n", + "1009948 66283 57.620720 2.000000 \n", + "7037361 66285 20.938625 0.000000 \n", + "5904487 66285 60.032860 2.000000 \n", + "694210 66287 38.335304 2.000000 \n", + "214174 66287 29.141777 0.000000 \n", + "9036872 66287 61.936405 2.000000 \n", + "11764210 66289 6.552125 0.000000 \n", + "11387051 66289 38.486992 1.854636 \n", + "11612100 66291 37.976425 0.000000 \n", + "3079584 66300 7.996721 0.000000 \n", + "13362800 66303 30.528870 0.000000 \n", + "6893820 66303 22.604115 0.000000 \n", + "5330874 66304 88.822281 2.000000 \n", + "5979517 66304 30.532675 0.000000 \n", + "3699961 66305 24.425629 0.000000 \n", + "2141920 66305 35.230000 0.000000 \n", + "14814610 66306 53.395950 1.000000 \n", + "8919220 66313 45.682854 1.035088 \n", + "9927843 66313 111.682037 3.789474 \n", + "9656810 66315 62.525566 0.000000 \n", + "11086890 66334 70.000000 0.000000 \n", + "6106609 66334 127.789474 2.000000 \n", + "1604820 66338 56.281395 2.000000 \n", + "10328782 66352 70.362518 2.964286 \n", + "12625210 66357 46.982361 2.000000 \n", + "10431751 66363 80.000000 0.000000 \n", + "7208328 66380 105.730003 0.000000 \n", + "\n", + " util_log_lot_capacity util_percent_drive \n", + "tour_id pnr_zone_id \n", + "9250500 66236 7.733684 0.141877 \n", + "4183761 66236 7.733684 0.125329 \n", + "4872110 66241 6.904751 0.929597 \n", + "3838500 66242 6.456770 0.404448 \n", + "11251300 66248 5.780744 0.458480 \n", + "1899200 66260 5.278115 0.358683 \n", + "6125890 66268 6.003887 0.138436 \n", + "14612890 66276 6.104793 0.746572 \n", + "3153800 66276 6.104793 0.277408 \n", + "4002057 66281 7.313887 0.119897 \n", + "7799961 66283 7.387090 0.319721 \n", + "2957820 66283 7.387090 0.209901 \n", + "1009948 66283 7.387090 0.293456 \n", + "7037361 66285 3.951244 0.606985 \n", + "5904487 66285 3.951244 0.518066 \n", + "694210 66287 6.666957 0.422467 \n", + "214174 66287 6.666957 0.276060 \n", + "9036872 66287 6.666957 0.238026 \n", + "11764210 66289 6.154858 0.845038 \n", + "11387051 66289 6.154858 0.639664 \n", + "11612100 66291 5.934894 0.131169 \n", + "3079584 66300 5.398163 0.839990 \n", + "13362800 66303 4.025352 0.480744 \n", + "6893820 66303 4.025352 0.576171 \n", + "5330874 66304 6.021023 0.078889 \n", + "5979517 66304 6.021023 0.196498 \n", + "3699961 66305 7.275865 0.581635 \n", + "2141920 66305 7.275865 0.277166 \n", + "14814610 66306 6.216606 0.241910 \n", + "8919220 66313 5.560682 0.566108 \n", + "9927843 66313 5.560682 0.652766 \n", + "9656810 66315 7.548029 0.199349 \n", + "11086890 66334 5.236442 0.237780 \n", + "6106609 66334 5.236442 0.291962 \n", + "1604820 66338 5.313206 0.125001 \n", + "10328782 66352 6.927558 0.565579 \n", + "12625210 66357 6.908755 0.183613 \n", + "10431751 66363 6.340359 0.340601 \n", + "7208328 66380 7.057037 0.282327 " + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x_ca.loc[is_chosen, predictor_cols]" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "activitysim (3.10.19)", + "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.10.19" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}