Data Module¶
The causalkit.data
module provides functions for generating synthetic data for causal inference tasks.
Overview¶
This module includes functions for generating:
- A/B test data with customizable parameters
- Randomized Controlled Trial (RCT) data
- Observational data for more complex causal inference scenarios
API Reference¶
Data generation utilities for causal inference tasks.
generate_obs_data(n_users=20000, split=0.1, random_state=42)
¶
Create synthetic observational data where treatment assignment is influenced by covariates.
Parameters¶
n_users Total number of users in the dataset. split Proportion of users in the treatment group. For example, 0.1 means 10% of users will be in the treatment group and 90% in the control group. random_state Seed for reproducibility.
Returns¶
pd.DataFrame Columns: user_id, treatment, age, income, education, gender, region
Source code in causalkit/data/generators.py
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 |
|
generate_rct_data(n_users=20000, split=0.5, random_state=42, target_type='binary', target_params=None)
¶
Create synthetic RCT data with • three possible target distributions (binary, continuous-normal, continuous-non-normal), • five covariates ─ age, cnt_trans, platform_Android, platform_iOS, invited_friend that are generated conditional on the target but remain independent of the treatment group (groups are perfectly randomised).
Parameters¶
n_users Total number of users in the dataset. split Proportion of users in the treatment group. For example, 0.5 means 50% of users will be in the treatment group and 50% in the control group. random_state Seed for reproducibility. target_type Target distribution: "binary", "normal", or "nonnormal". target_params Distribution parameters. If None sensible defaults are used: binary : {"p": {"A": 0.10, "B": 0.12}} normal : {"mean": {"A": 0.00, "B": 0.20}, "std": 1.0} nonnormal: {"shape": 2.0, "scale": {"A": 1.0, "B": 1.1}}
Returns¶
pd.DataFrame Columns: user_id, treatment, target, age, cnt_trans, platform_Android, platform_iOS, invited_friend.
Source code in causalkit/data/generators.py
16 17 18 19 20 21 22 23 24 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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|