View#

from tmlt.tune import View
class tmlt.tune.View(name, func)#

Bases: object

Wrapper to allow users to define a view of the output table.

If the program has outputs, unprotected inputs or parameters, the view method can pass outputs, unprotected_inputs and/or parameters arguments and the value gets auto-populated from the program.

>>> from tmlt.analytics import Session
>>> from tmlt.tune import MedianRelativeError
>>> class Program(SessionProgram):
...     class ProtectedInputs:
...         protected_df: DataFrame
...     class UnprotectedInputs:
...         unprotected_df: DataFrame
...     class Outputs:
...         output_df: DataFrame
...     def session_interaction(self, session: Session):
...         ...
>>> class Tuner(SessionProgramTuner, program=Program):
...     @view("output_view")
...     @staticmethod
...     def custom_view1(
...         outputs: Dict[str, DataFrame],
...     ) -> DataFrame:
...         ...
...
...     def create_custom_view2(arbitrary_param):
...         def custom_view2(outputs: Dict[str, DataFrame]) -> DataFrame:
...             assert arbitrary_param == ["a", "b"]
...             return outputs["output_df"].groupby(arbitrary_param).sum()
...         return custom_view2
...
...     views = [
...               View(
...                    name="another_output_view",
...                    func=create_custom_view2(["a", "b"])
...               )
...     ]
...     metrics = [
...         MedianRelativeError(
...             output="another_output_view",
...             measure_column="a_sum",
...             join_columns=["a"],
...         ),
...     ] # The view can be used instead of output when metric is defined
property name: str#

Returns the name of the metric.

property func: Callable#

Function that returns rhe actual view.