tea_tasting.datasets
#
Example datasets.
make_users_data(*, covariates=False, seed=None, n_users=4000, ratio=1, sessions_uplift=0.0, orders_uplift=0.1, revenue_uplift=0.1, avg_sessions=2, avg_orders_per_session=0.25, avg_revenue_per_order=10, return_type='arrow')
#
Generate simulated data for A/B testing scenarios.
Data mimics what you might encounter in an A/B test for an online store, with a user-level randomization. Each row represents an individual user with information about:
user
: User identifier.variant
: Variant of the test. 0 is control, 1 is treatment.sessions
: Number of user's sessions.orders
: Number of user's orders.revenue
: Revenue generated by the user.
Optionally, pre-experimental data can be generated as well:
sessions_covariate
: Number of user's sessions before the experiment.orders_covariate
: Number of user's orders before the experiment.revenue_covariate
: Revenue generated by the user before the experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
covariates |
bool
|
If |
False
|
seed |
int | Generator | SeedSequence | None
|
Random seed. |
None
|
n_users |
int
|
Number of users. |
4000
|
ratio |
float | int
|
Ratio of the number of users in treatment relative to control. |
1
|
sessions_uplift |
float | int
|
Sessions uplift in the treatment variant, relative to control. |
0.0
|
orders_uplift |
float
|
Orders uplift in the treatment variant, relative to control. |
0.1
|
revenue_uplift |
float
|
Revenue uplift in the treatment variant, relative to control. |
0.1
|
avg_sessions |
float | int
|
Average number of sessions per user. |
2
|
avg_orders_per_session |
float
|
Average number of orders per session.
Should be less than |
0.25
|
avg_revenue_per_order |
float | int
|
Average revenue per order. |
10
|
return_type |
Literal['arrow', 'pandas', 'polars']
|
Return type:
|
'arrow'
|
Returns:
Type | Description |
---|---|
Table | Any | Any
|
Simulated data for A/B testing scenarios. |
Examples:
>>> import tea_tasting as tt
>>> data = tt.make_users_data(seed=42)
>>> print(data)
pyarrow.Table
user: int64
variant: int64
sessions: int64
orders: int64
revenue: double
----
user: [[0,1,2,3,4,...,3995,3996,3997,3998,3999]]
variant: [[1,0,1,1,0,...,0,0,0,0,0]]
sessions: [[2,2,2,2,1,...,2,2,3,1,5]]
orders: [[1,1,1,1,1,...,0,0,0,0,2]]
revenue: [[9.17,6.43,7.94,15.93,7.14,...,0,0,0,0,17.16]]
With covariates:
>>> data = tt.make_users_data(seed=42, covariates=True)
>>> print(data)
pyarrow.Table
user: int64
variant: int64
sessions: int64
orders: int64
revenue: double
sessions_covariate: int64
orders_covariate: int64
revenue_covariate: double
----
user: [[0,1,2,3,4,...,3995,3996,3997,3998,3999]]
variant: [[1,0,1,1,0,...,0,0,0,0,0]]
sessions: [[2,2,2,2,1,...,2,2,3,1,5]]
orders: [[1,1,1,1,1,...,0,0,0,0,2]]
revenue: [[9.17,6.43,7.94,15.93,7.14,...,0,0,0,0,17.16]]
sessions_covariate: [[3,4,4,1,1,...,1,3,2,1,5]]
orders_covariate: [[2,1,2,0,1,...,0,1,0,0,0]]
revenue_covariate: [[19.19,2.77,22.57,0,13.68,...,0,13.52,0,0,0]]
As Pandas DataFrame:
>>> data = tt.make_users_data(seed=42, return_type="pandas")
>>> print(data)
user variant sessions orders revenue
0 0 1 2 1 9.17
1 1 0 2 1 6.43
2 2 1 2 1 7.94
3 3 1 2 1 15.93
4 4 0 1 1 7.14
... ... ... ... ... ...
3995 3995 0 2 0 0.00
3996 3996 0 2 0 0.00
3997 3997 0 3 0 0.00
3998 3998 0 1 0 0.00
3999 3999 0 5 2 17.16
[4000 rows x 5 columns]
As Polars DataFrame:
>>> data = tt.make_users_data(seed=42, return_type="polars")
>>> print(data)
shape: (4_000, 5)
┌──────┬─────────┬──────────┬────────┬─────────┐
│ user ┆ variant ┆ sessions ┆ orders ┆ revenue │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 ┆ i64 ┆ f64 │
╞══════╪═════════╪══════════╪════════╪═════════╡
│ 0 ┆ 1 ┆ 2 ┆ 1 ┆ 9.17 │
│ 1 ┆ 0 ┆ 2 ┆ 1 ┆ 6.43 │
│ 2 ┆ 1 ┆ 2 ┆ 1 ┆ 7.94 │
│ 3 ┆ 1 ┆ 2 ┆ 1 ┆ 15.93 │
│ 4 ┆ 0 ┆ 1 ┆ 1 ┆ 7.14 │
│ … ┆ … ┆ … ┆ … ┆ … │
│ 3995 ┆ 0 ┆ 2 ┆ 0 ┆ 0.0 │
│ 3996 ┆ 0 ┆ 2 ┆ 0 ┆ 0.0 │
│ 3997 ┆ 0 ┆ 3 ┆ 0 ┆ 0.0 │
│ 3998 ┆ 0 ┆ 1 ┆ 0 ┆ 0.0 │
│ 3999 ┆ 0 ┆ 5 ┆ 2 ┆ 17.16 │
└──────┴─────────┴──────────┴────────┴─────────┘
Source code in src/tea_tasting/datasets.py
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 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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
make_sessions_data(*, covariates=False, seed=None, n_users=4000, ratio=1, sessions_uplift=0.0, orders_uplift=0.1, revenue_uplift=0.1, avg_sessions=2, avg_orders_per_session=0.25, avg_revenue_per_order=10, return_type='arrow')
#
Generate simulated user data for A/B testing scenarios.
Data mimics what you might encounter in an A/B test for an online store, with a user-level randomization. Each row represents a user's session with information about:
user
: User identifier.variant
: Variant of the test. 0 is control, 1 is treatment.sessions
: Number of user's sessions.orders
: Number of user's orders.revenue
: Revenue generated by the user.
Optionally, pre-experimental data can be generated as well:
sessions_covariate
: Number of user's sessions before the experiment.orders_covariate
: Number of user's orders before the experiment.revenue_covariate
: Revenue generated by the user before the experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
covariates |
bool
|
If |
False
|
seed |
int | Generator | SeedSequence | None
|
Random seed. |
None
|
n_users |
int
|
Number of users. |
4000
|
ratio |
float | int
|
Ratio of the number of users in treatment relative to control. |
1
|
sessions_uplift |
float | int
|
Sessions uplift in the treatment variant, relative to control. |
0.0
|
orders_uplift |
float
|
Orders uplift in the treatment variant, relative to control. |
0.1
|
revenue_uplift |
float
|
Revenue uplift in the treatment variant, relative to control. |
0.1
|
avg_sessions |
float | int
|
Average number of sessions per user. |
2
|
avg_orders_per_session |
float
|
Average number of orders per session.
Should be less than |
0.25
|
avg_revenue_per_order |
float | int
|
Average revenue per order. |
10
|
return_type |
Literal['arrow', 'pandas', 'polars']
|
Return type:
|
'arrow'
|
Returns:
Type | Description |
---|---|
Table | Any | Any
|
Simulated data for A/B testing scenarios. |
Examples:
>>> import tea_tasting as tt
>>> data = tt.make_sessions_data(seed=42)
>>> data
pyarrow.Table
user: int64
variant: int64
sessions: int64
orders: int64
revenue: double
----
user: [[0,0,1,1,2,...,3999,3999,3999,3999,3999]]
variant: [[1,1,0,0,1,...,0,0,0,0,0]]
sessions: [[1,1,1,1,1,...,1,1,1,1,1]]
orders: [[1,1,1,1,1,...,1,0,1,1,0]]
revenue: [[5.89,6.13,2.61,12.3,11.57,...,23.63,0,2.4,24.54,0]]
With covariates:
>>> data = tt.make_sessions_data(seed=42, covariates=True)
>>> data
pyarrow.Table
user: int64
variant: int64
sessions: int64
orders: int64
revenue: double
sessions_covariate: double
orders_covariate: double
revenue_covariate: double
----
user: [[0,0,1,1,2,...,3999,3999,3999,3999,3999]]
variant: [[1,1,0,0,1,...,0,0,0,0,0]]
sessions: [[1,1,1,1,1,...,1,1,1,1,1]]
orders: [[1,1,1,1,1,...,1,0,1,1,0]]
revenue: [[5.89,6.13,2.61,12.3,11.57,...,23.63,0,2.4,24.54,0]]
sessions_covariate: [[1.5,1.5,0,0,1.5,...,0.2,0.2,0.2,0.2,0.2]]
orders_covariate: [[0.5,0.5,0,0,1.5,...,0,0,0,0,0]]
revenue_covariate: [[1.24,1.24,0,0,12.32,...,0,0,0,0,0]]
As Pandas DataFrame:
>>> data = tt.make_sessions_data(seed=42, return_type="pandas")
>>> print(data)
user variant sessions orders revenue
0 0 1 1 1 5.89
1 0 1 1 1 6.13
2 1 0 1 1 2.61
3 1 0 1 1 12.30
4 2 1 1 1 11.57
... ... ... ... ... ...
7953 3999 0 1 1 23.63
7954 3999 0 1 0 0.00
7955 3999 0 1 1 2.40
7956 3999 0 1 1 24.54
7957 3999 0 1 0 0.00
[7958 rows x 5 columns]
As Polars DataFrame:
>>> data = tt.make_sessions_data(seed=42, return_type="polars")
>>> print(data)
shape: (7_958, 5)
┌──────┬─────────┬──────────┬────────┬─────────┐
│ user ┆ variant ┆ sessions ┆ orders ┆ revenue │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 ┆ i64 ┆ f64 │
╞══════╪═════════╪══════════╪════════╪═════════╡
│ 0 ┆ 1 ┆ 1 ┆ 1 ┆ 5.89 │
│ 0 ┆ 1 ┆ 1 ┆ 1 ┆ 6.13 │
│ 1 ┆ 0 ┆ 1 ┆ 1 ┆ 2.61 │
│ 1 ┆ 0 ┆ 1 ┆ 1 ┆ 12.3 │
│ 2 ┆ 1 ┆ 1 ┆ 1 ┆ 11.57 │
│ … ┆ … ┆ … ┆ … ┆ … │
│ 3999 ┆ 0 ┆ 1 ┆ 1 ┆ 23.63 │
│ 3999 ┆ 0 ┆ 1 ┆ 0 ┆ 0.0 │
│ 3999 ┆ 0 ┆ 1 ┆ 1 ┆ 2.4 │
│ 3999 ┆ 0 ┆ 1 ┆ 1 ┆ 24.54 │
│ 3999 ┆ 0 ┆ 1 ┆ 0 ┆ 0.0 │
└──────┴─────────┴──────────┴────────┴─────────┘
Source code in src/tea_tasting/datasets.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|