Pipeline
Pipeline for chaining multiple operations.
Pipeline
Pipeline
Bases: AbobaBase
A sequence of data preprocessors with one optional splitter.
Pipeline allows you to sequentially apply preprocessors to your data. If splitter is given then, when its turn comes, the groups are sampled from the data and the following preprocessors will be applied to each group produced by the splitter.
The pipeline accumulates artifacts from all processors and returns them along with the transformed data. Supports both old-style processors (returning only data or (data,)) and new-style (returning (data, artifacts)).
Examples:
from aboba import tests
from aboba import splitters
from aboba import effect_modifiers
from aboba import processing
from aboba import pipelines
import numpy as np
import pandas as pd
import scipy.stats as sps
data_a = sps.norm.rvs(size=1000, loc=0, scale=100)
data_b = sps.norm.rvs(size=1000, loc=0, scale=100)
data_a_cov = data_a + sps.norm.rvs(size=1000, loc=0, scale=0.5)
data_b_cov = data_b + sps.norm.rvs(size=1000, loc=0, scale=0.5)
data_a_strat = sps.bernoulli.rvs(p=0.15, size=1000)
data_b_strat = sps.bernoulli.rvs(p=0.15, size=1000)
# dataset of two columns: value and group
data = pd.DataFrame({
'value': np.concatenate([
data_a,
data_b,
]),
'covariate': np.concatenate([
data_a_cov,
data_b_cov,
]),
'strat': np.concatenate([
data_a_strat,
data_b_strat,
]),
'b_group': np.concatenate([
np.repeat(0, 1000),
np.repeat(1, 1000),
]),
})
cuped_preprocess = processing.CupedProcessor(
value_column='value',
covariate_columns='covariate',
result_column='value',
group_column='b_group',
group_test=1,
group_control=0,
)
ensurecol_preprocess = processing.EnsureColsProcessor(cols=['value', 'covariate'])
pipeline_cuped = pipelines.Pipeline([
('cuped', cuped_preprocess),
('splitter', splitter),
('ensurecols', ensurecol_preprocess)
])
pipeline_cuped.fit(data)
result_data, artifacts = pipeline_cuped.transform(data)
# Or if you don't need artifacts:
result_data, _ = pipeline_cuped.transform(data)
# Check for CUPED artifacts
if 'cuped_original_control_mean' in artifacts:
print(f"Original control mean: {artifacts['cuped_original_control_mean']}")
Source code in aboba/pipeline/pipeline.py
8 9 10 11 12 13 14 15 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 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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
__init__
__init__(steps: List[Union[Tuple[str, Union[BaseDataSplitter, BaseDataProcessor]], BaseDataSplitter, BaseDataProcessor]])
Initialize the pipeline with a list of transformers.
| PARAMETER | DESCRIPTION |
|---|---|
steps
|
List of transformers. Each step can be: - A tuple (name, transformer) - Just a transformer (name will be auto-generated)
TYPE:
|
Source code in aboba/pipeline/pipeline.py
transform
Apply all transformers in the pipeline to the provided data.
Accumulates artifacts from all processors and returns them along with transformed data. Supports both old-style processors (returning only data) and new-style (returning (data, artifacts)).
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Input data (pd.DataFrame, List[pd.DataFrame], or callable returning such)
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[Union[DataFrame, List[DataFrame]], Dict[str, Any]]
|
Tuple[Union[pd.DataFrame, List[pd.DataFrame]], Dict[str, Any]]: - Transformed data (single DataFrame or list of DataFrames after splitting) - Accumulated artifacts dictionary from all processors |
Examples:
# Get both data and artifacts
transformed_data, artifacts = pipeline.transform(data)
# If you don't need artifacts
transformed_data, _ = pipeline.transform(data)
# Check for CUPED artifacts
if 'cuped_original_control_mean' in artifacts:
print(f"Original control mean: {artifacts['cuped_original_control_mean']}")
Source code in aboba/pipeline/pipeline.py
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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
fit_transform
Fit the pipeline and transform data in one step.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Input data
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[Union[DataFrame, List[DataFrame]], Dict[str, Any]]
|
Tuple[Union[pd.DataFrame, List[pd.DataFrame]], Dict[str, Any]]: Transformed data and accumulated artifacts |