Model API
lefts.interface.Model
dataclass
Source code in src/lefts/interface.py
fit(df, logging='capture', errors='raise')
Fit every leaf model in the tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logging
|
Literal['capture', 'drop', 'print']
|
Determines how we handle each leaf model's stdout/stderr during fit: - print: stdout/stderr from each model will behave as normal - drop: stdout/stderr from all models will be dropped. - capture: collects it into self.logs keyed by model label. |
'capture'
|
errors
|
Literal['capture', 'raise']
|
Determines how we handle exceptions that raise during fit: - raise: an error in the fit of any leaf halts the fit call - capture: records the exception in self.exceptions, keyed by model label, and continues fitting the remaining models. |
'raise'
|
Source code in src/lefts/interface.py
mark_train_validation_test_rows(df)
Annotate df with boolean columns describing whether each
row belongs to the train, test and (if applicable) validation
sets for each sub model.
Source code in src/lefts/interface.py
predict(df, errors='raise')
Run predict for every fitted leaf model in the tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
errors
|
Literal['raise', 'skip_unfit_models', 'output_nan']
|
Determines how leaf models that were not fitted (e.g. because fit was called with errors='capture' and they raised) are handled during predict: - raise: raises a RuntimeError if any model is missing from self.models. - skip_unfit_models: silently omits the output column for any unfit model. - output_nan: adds the output column but fills it entirely with null. |
'raise'
|