Skip to content

featurebyte.Treatment.create

create(
name: str,
dtype: DBVarType,
treatment_type: TreatmentType,
source: AssignmentSource,
design: AssignmentDesign,
time: TreatmentTime="static",
time_structure: TreatmentTimeStructure="none",
interference: TreatmentInterference="none",
treatment_labels: Optional[List[Union[str, int, bool]]]=None,
control_label: Union[str, int, bool, NoneType]=None,
propensity: Optional[Propensity]=None
) -> Treatment

Description

Create a new Treatment.

Parameters

  • name: str
    Name of the Treatment

  • dtype: DBVarType
    Data type of the Treatment

  • treatment_type: TreatmentType
    Scale of the treatment variable.
    Valid values:

    - binary:
    Two-level treatment (for example, exposed vs control, coupon vs no coupon).
    - multi_arm:
    Discrete treatment with more than two levels (dosage tiers, variants).
    - continuous:
    Numeric treatment representing a dose, price, spend, or intensity.
    Suitable for dose response estimators such as DR-learner and
    continuous treatment DML or orthogonal ML.

  • source: AssignmentSource
    High level source of treatment assignment. Determines the identification strategy and whether uplift style modeling is valid.

  • design: AssignmentDesign
    Specific assignment design within the chosen source.

  • time: TreatmentTime
    default: "static"
    Time at which treatment is defined, for example static or time varying.

  • time_structure: TreatmentTimeStructure
    default: "none"
    Detailed temporal structure of the treatment process.

  • interference: TreatmentInterference
    default: "none"
    Structure of interference between units (violations of SUTVA).

  • treatment_labels: Optional[List[Union[str, int, bool]]]
    List of raw treatment values used in the dataset.
    Constraints

    - For continuous treatments, this must be None.
    - For binary treatments, this must be provided and contain exactly two values.
    - For multi_arm treatments, this must be provided and contain at least two values.

  • control_label: Union[str, int, bool, NoneType]
    Value representing the control or baseline arm.
    Constraints

    - For continuous treatments, this must be None.
    - For binary and multi_arm treatments, this must be provided and
    must be one of treatment_labels.

  • propensity: Optional[Propensity]
    Optional Propensity specification describing how treatment assignment probabilities p(T | ·) are known or estimated.
    Constraints

    - For continuous treatments, propensity must be None.

Returns

  • Treatment
    The created Treatment

Examples

Example 1: Simple A/B Test With Known Global Propensity

>>> treatment = fb.Treatment.create(
...     name="Churn Campaign A/B test",
...     dtype=DBVarType.INT,
...     treatment_type=fb.TreatmentType.BINARY,
...     source="randomized",
...     design="simple-randomization",
...     time="static",
...     time_structure="instantaneous",
...     interference="none",
...     treatment_labels=[0, 1],
...     control_label=0,
...     propensity=fb.Propensity(
...         granularity="global",
...         knowledge="design-known",
...         p_global=0.5,  # 50/50 experiment
...     ),
... )
Example 2: Observational Treatment With Estimated Unit-Level Propensity

>>> observational_treatment = fb.Treatment.create(
...     name="Churn Campaign",
...     dtype=DBVarType.INT,
...     treatment_type=fb.TreatmentType.BINARY,
...     source="observational",
...     design="business-rule",
...     time="static",
...     time_structure="none",
...     interference="none",
...     treatment_labels=[0, 1],
...     control_label=0,
...     propensity=fb.Propensity(
...         granularity="unit",
...         knowledge="estimated",  # Requires model-based p(T|X)
...     ),
... )

See Also