In [1]:
import larch
import pandas
from larch import PX, P, X
In [2]:
from larch.data_warehouse import example_file
df = pandas.read_csv(example_file("MTCwork.csv.gz"))
df.set_index(['casenum','altnum'], inplace=True, drop=False)
In [3]:
m = larch.Model()
m.utility_ca = (
PX('tottime')
+ PX('totcost')
+ sum(P(f'ASC_{i}') * X(f'altnum=={i}') for i in [2,3,4,5,6])
+ sum(P(f'HHINC#{i}') * X(f'(altnum=={i})*hhinc') for i in [2,3,4,5,6])
)
In [4]:
m.fit(df, y=df.chose)
Out[4]:
In [5]:
proba = m.predict_proba(df)
proba.head(10)
Out[5]:
In [6]:
score = m.score(df, y=df.chose)
score
Out[6]:
In [7]:
score * m.dataframes.n_cases
Out[7]: