File tree Expand file tree Collapse file tree 2 files changed +5
-33
lines changed Expand file tree Collapse file tree 2 files changed +5
-33
lines changed Original file line number Diff line number Diff line change 8282- New handler types can be easily added (e.g., multiple intervention times)
8383- Code is maintainable and testable with clear separation of concerns
8484
85- Usage Examples
86- --------------
87- Known treatment time (traditional approach):
88-
89- >>> result = cp.ChangePointDetection(
90- ... data=df,
91- ... time_range=None
92- ... formula="y ~ 1 + t + C(month)",
93- ... model=cp.pymc_models.LinearChangePointDetection(),
94- ... )
95-
9685The module automatically selects the appropriate handler based on the treatment_time
9786parameter and model type, providing a seamless user experience while maintaining
9887the flexibility to handle diverse analytical scenarios.
@@ -138,18 +127,18 @@ class ChangePointDetection(BaseExperiment):
138127 ... .assign(date=lambda x: pd.to_datetime(x["date"]))
139128 ... .set_index("date")
140129 ... )
141- >>> treatment_time = pd.to_datetime("2017-01-01")
142130 >>> seed = 42
143- >>> result = cp.InterruptedTimeSeries (
131+ >>> result = cp.experiments.change_point_detection.ChangePointDetection (
144132 ... df,
145- ... treatment_time ,
133+ ... time_range=None ,
146134 ... formula="y ~ 1 + t + C(month)",
147- ... model=cp.pymc_models.LinearRegression(
135+ ... model=cp.pymc_models.LinearChangePointDetection(
136+ ... cp_effect_type="level",
148137 ... sample_kwargs={
149138 ... "target_accept": 0.95,
150139 ... "random_seed": seed,
151140 ... "progressbar": False,
152- ... }
141+ ... },
153142 ... ),
154143 ... )
155144 """
Original file line number Diff line number Diff line change 8686--------------
8787Known treatment time (traditional approach):
8888
89- >>> result = cp.InterruptedTimeSeries(
90- ... data=df,
91- ... treatment_time=pd.to_datetime("2017-01-01"), # Known intervention
92- ... formula="y ~ 1 + t + C(month)",
93- ... model=cp.pymc_models.LinearRegression(),
94- ... )
95-
96- Unknown treatment time (inference approach):
97-
98- >>> model = cp.pymc_models.InterventionTimeEstimator(treatment_effect_type="level")
99- >>> result = cp.InterruptedTimeSeries(
100- ... data=df,
101- ... treatment_time=None, # Let model infer the time
102- ... formula="y ~ 1 + t + C(month)",
103- ... model=model,
104- ... )
105-
10689The module automatically selects the appropriate handler based on the treatment_time
10790parameter and model type, providing a seamless user experience while maintaining
10891the flexibility to handle diverse analytical scenarios.
You can’t perform that action at this time.
0 commit comments