from cluster_experiments.cupac import *
¶
CupacHandler
¶
CupacHandler class. It handles operations related to the cupac model.
Its main goal is to call the add_covariates method, where it will add the ouptut from the cupac model, and this should be used as covariates in the regression method for the hypothesis test.
Source code in cluster_experiments/cupac.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
add_covariates(df, pre_experiment_df=None)
¶
Train model to predict outcome variable (based on pre-experiment data) and add the prediction to the experiment dataframe. Only do this if we use cupac Args: pre_experiment_df: Dataframe with pre-experiment data. df: Dataframe with outcome and treatment variables.
Source code in cluster_experiments/cupac.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
EmptyRegressor
¶
Bases: BaseEstimator
Empty regressor class. It does not do anything, used to glue the code of other estimators and PowerAnalysis
Each Regressor should have: - fit method: Uses pre experiment data to fit some kind of model to be used as a covariate and reduce variance. - predict method: Uses the fitted model to add the covariate on the experiment data.
It can add aggregates of the target in older data as a covariate, or a model (cupac) to predict the target.
Source code in cluster_experiments/cupac.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
TargetAggregation
¶
Bases: BaseEstimator
Adds average of target using pre-experiment data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agg_col
|
str
|
Column to group by to aggregate target |
required |
target_col
|
str
|
Column to aggregate |
'target'
|
smoothing_factor
|
int
|
Smoothing factor for the smoothed mean |
20
|
Usage:
import pandas as pd
from cluster_experiments.cupac import TargetAggregation
df = pd.DataFrame({"agg_col": ["a", "a", "b", "b", "c", "c"], "target_col": [1, 2, 3, 4, 5, 6]})
new_df = pd.DataFrame({"agg_col": ["a", "a", "b", "b", "c", "c"]})
target_agg = TargetAggregation("agg_col", "target_col")
target_agg.fit(df.drop(columns="target_col"), df["target_col"])
df_with_target_agg = target_agg.predict(new_df)
print(df_with_target_agg)
Source code in cluster_experiments/cupac.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
fit(X, y)
¶
Fits "target encoder" model to pre-experiment data
Source code in cluster_experiments/cupac.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
from_config(config)
classmethod
¶
Creates TargetAggregation from PowerConfig
Source code in cluster_experiments/cupac.py
98 99 100 101 102 103 104 105 |
|
predict(X)
¶
Adds average target of pre-experiment data to experiment data
Source code in cluster_experiments/cupac.py
88 89 90 91 92 93 94 95 96 |
|