Constructed
physXAI.preprocessing.constructed
Attributes
CONSTRUCTED_CLASS_REGISTRY: dict[str, Type[FeatureBase]] = dict()
module-attribute
Classes
FeatureBase
Bases: ABC
Abstract Base Class for all feature engineering components. Each feature object represents a column (or a transformation that results in a column) in a Pandas DataFrame. It supports arithmetic operations to combine features.
Source code in physXAI/preprocessing/constructed.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 | |
Attributes
feature: str = name
instance-attribute
Functions
__init__(name: str, **kwargs)
Initializes a FeatureBase instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the feature. This will be the column name in the DataFrame. |
required |
**kwargs
|
Catches any additional keyword arguments. |
{}
|
Source code in physXAI/preprocessing/constructed.py
15 16 17 18 19 20 21 22 23 24 25 26 27 | |
rename(name: str)
Renames the feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The new name for the feature. |
required |
Source code in physXAI/preprocessing/constructed.py
29 30 31 32 33 34 35 36 37 | |
process(df: DataFrame) -> Series
Processes the DataFrame to return the Series corresponding to this feature. For a base feature that already exists in the DataFrame, it simply returns the column. For derived features, this method would compute the feature if it doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Series |
Series
|
The Pandas Series representing this feature. |
Source code in physXAI/preprocessing/constructed.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
exp()
Creates a new feature representing e^(self).
Source code in physXAI/preprocessing/constructed.py
84 85 86 | |
sin()
Creates a new feature representing sin(self).
Source code in physXAI/preprocessing/constructed.py
88 89 90 | |
cos()
Creates a new feature representing cos(self).
Source code in physXAI/preprocessing/constructed.py
92 93 94 | |
lag(lag: int, previous: bool = True)
Creates a lagged version of this feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lag
|
int
|
The number of time steps to lag by. |
required |
previous
|
bool
|
If True and lag_value > 1, returns a list of FeatureLag objects for all lags from 1 up to lag_value. Otherwise, returns a single FeatureLag object for the specified lag_value. |
True
|
Returns:
| Type | Description |
|---|---|
|
FeatureLag or List[FeatureLag]: A single lagged feature or a list of lagged features. |
Source code in physXAI/preprocessing/constructed.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
get_config() -> dict
Source code in physXAI/preprocessing/constructed.py
118 119 120 | |
from_config(config: dict) -> FeatureBase
classmethod
Source code in physXAI/preprocessing/constructed.py
122 123 124 | |
Feature
Bases: FeatureBase
Represents a basic feature that is assumed to exist directly in the input DataFrame.
Its process method simply retrieves the column by its name.
Source code in physXAI/preprocessing/constructed.py
164 165 166 167 168 169 170 | |
FeatureLag
Bases: FeatureBase
Represents a lagged version of another feature.
Calculates df[original_feature_name].shift(lag_steps).
Source code in physXAI/preprocessing/constructed.py
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 | |
Attributes
origf: str = f.feature
instance-attribute
lag: int = lag
instance-attribute
Functions
__init__(f: Union[FeatureBase, str], lag: int, name: str = None, **kwargs)
Initializes a FeatureLag instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
FeatureBase or str
|
The original feature object or its name. |
required |
lag
|
int
|
The number of time steps to lag by. |
required |
name
|
str
|
The name for this lagged feature. If None, it's auto-generated as "{original_name}_lag{X}". |
None
|
**kwargs
|
Catches any additional keyword arguments. |
{}
|
Source code in physXAI/preprocessing/constructed.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
process(df: DataFrame) -> Series
Source code in physXAI/preprocessing/constructed.py
200 201 202 203 | |
get_config() -> dict
Source code in physXAI/preprocessing/constructed.py
205 206 207 208 | |
FeatureTwo
Bases: FeatureBase, ABC
Abstract Base Class for features derived from two other features (or constants). Examples: FeatureAdd (f1 + f2), FeatureSub (f1 - f2).
Source code in physXAI/preprocessing/constructed.py
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 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 | |
Attributes
feature1 = feature1
instance-attribute
feature2 = feature2
instance-attribute
Functions
__init__(feature1: Union[FeatureBase, int, float], feature2: Union[FeatureBase, int, float], name: str = None, **kwargs)
Initializes a FeatureTwo instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature1
|
FeatureBase or int or float
|
The first operand. |
required |
feature2
|
FeatureBase or int or float
|
The second operand. |
required |
name
|
str
|
Name for the derived feature. If None, it's auto-generated
by the |
None
|
**kwargs
|
Catches any additional keyword arguments. |
{}
|
Source code in physXAI/preprocessing/constructed.py
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 | |
process(df: DataFrame) -> Series
Calculates and returns the derived feature Series.
If the column doesn't exist, it processes the operand features (if they are FeatureBase objects)
or uses the constant values, then applies the calc method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Series |
Series
|
The derived feature Series. |
Source code in physXAI/preprocessing/constructed.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
calc(f1, f2)
abstractmethod
Abstract method to perform the actual calculation between the two processed operands. To be implemented by subclasses (e.g., addition, subtraction).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f1
|
The processed first operand (either a Series or a scalar). |
required | |
f2
|
The processed second operand (either a Series or a scalar). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Series |
The result of the calculation. |
Source code in physXAI/preprocessing/constructed.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
name(f1: str, f2: str) -> str
abstractmethod
Abstract method to generate a descriptive name for the derived feature, based on the names of its operands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f1
|
str
|
Name of the first operand. |
required |
f2
|
str
|
Name of the second operand. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The auto-generated name for this feature. |
Source code in physXAI/preprocessing/constructed.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
get_config() -> dict
Returns the configuration for FeatureTwo. Includes configurations of its operand features if they are FeatureBase objects, or the constant values otherwise.
Source code in physXAI/preprocessing/constructed.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
from_config(config: dict) -> FeatureTwo
classmethod
Creates a FeatureTwo instance (or its subclass) from a configuration dictionary. Handles reconstruction of operand features if they were FeatureBase objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict
|
Configuration dictionary. Must contain 'feature1' and 'feature2'. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FeatureTwo |
FeatureTwo
|
An instance of the specific FeatureTwo subclass. |
Source code in physXAI/preprocessing/constructed.py
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 | |
FeatureAdd
Bases: FeatureTwo
Source code in physXAI/preprocessing/constructed.py
360 361 362 363 364 365 366 367 | |
Functions
calc(f1, f2)
Source code in physXAI/preprocessing/constructed.py
363 364 | |
name(f1: str, f2: str) -> str
Source code in physXAI/preprocessing/constructed.py
366 367 | |
FeatureSub
Bases: FeatureTwo
Source code in physXAI/preprocessing/constructed.py
370 371 372 373 374 375 376 377 | |
Functions
calc(f1, f2)
Source code in physXAI/preprocessing/constructed.py
373 374 | |
name(f1: str, f2: str) -> str
Source code in physXAI/preprocessing/constructed.py
376 377 | |
FeatureMul
Bases: FeatureTwo
Source code in physXAI/preprocessing/constructed.py
380 381 382 383 384 385 386 387 | |
Functions
calc(f1, f2)
Source code in physXAI/preprocessing/constructed.py
383 384 | |
name(f1: str, f2: str) -> str
Source code in physXAI/preprocessing/constructed.py
386 387 | |
FeatureTrueDiv
Bases: FeatureTwo
Source code in physXAI/preprocessing/constructed.py
390 391 392 393 394 395 396 397 | |
Functions
calc(f1, f2)
Source code in physXAI/preprocessing/constructed.py
393 394 | |
name(f1: str, f2: str) -> str
Source code in physXAI/preprocessing/constructed.py
396 397 | |
FeaturePow
Bases: FeatureTwo
Source code in physXAI/preprocessing/constructed.py
400 401 402 403 404 405 406 407 | |
Functions
calc(f1, f2)
Source code in physXAI/preprocessing/constructed.py
403 404 | |
name(f1: str, f2: str) -> str
Source code in physXAI/preprocessing/constructed.py
406 407 | |
FeatureExp
Bases: FeatureBase
Feature representing e^(feature).
Source code in physXAI/preprocessing/constructed.py
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 | |
Attributes
f1: FeatureBase = f1
instance-attribute
Functions
__init__(f1: FeatureBase, name: str = None, **kwargs)
Source code in physXAI/preprocessing/constructed.py
414 415 416 417 418 | |
process(df: DataFrame) -> Series
Source code in physXAI/preprocessing/constructed.py
420 421 422 423 | |
get_config() -> dict
Source code in physXAI/preprocessing/constructed.py
425 426 427 428 | |
from_config(config: dict) -> FeatureExp
classmethod
Source code in physXAI/preprocessing/constructed.py
430 431 432 433 434 435 436 437 | |
FeatureSin
Bases: FeatureBase
Feature representing sin(feature).
Source code in physXAI/preprocessing/constructed.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
Attributes
f1: FeatureBase = f1
instance-attribute
Functions
__init__(f1: FeatureBase, name: str = None, **kwargs)
Source code in physXAI/preprocessing/constructed.py
444 445 446 447 448 | |
process(df: DataFrame) -> Series
Source code in physXAI/preprocessing/constructed.py
450 451 452 453 | |
get_config() -> dict
Source code in physXAI/preprocessing/constructed.py
455 456 457 458 | |
from_config(config: dict) -> FeatureSin
classmethod
Source code in physXAI/preprocessing/constructed.py
460 461 462 463 464 465 466 467 | |
FeatureCos
Bases: FeatureBase
Feature representing cos(feature).
Source code in physXAI/preprocessing/constructed.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
Attributes
f1: FeatureBase = f1
instance-attribute
Functions
__init__(f1: FeatureBase, name: str = None, **kwargs)
Source code in physXAI/preprocessing/constructed.py
474 475 476 477 478 | |
process(df: DataFrame) -> Series
Source code in physXAI/preprocessing/constructed.py
480 481 482 483 | |
get_config() -> dict
Source code in physXAI/preprocessing/constructed.py
485 486 487 488 | |
from_config(config: dict) -> FeatureCos
classmethod
Source code in physXAI/preprocessing/constructed.py
490 491 492 493 494 495 496 497 | |
FeatureConstant
Bases: FeatureBase
Represents a feature that is a constant value across all rows.
Source code in physXAI/preprocessing/constructed.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
Attributes
c = c
instance-attribute
Functions
__init__(c: float, name: str, **kwargs)
Source code in physXAI/preprocessing/constructed.py
506 507 508 | |
process(df: DataFrame) -> Series
Source code in physXAI/preprocessing/constructed.py
510 511 512 513 | |
get_config() -> dict
Source code in physXAI/preprocessing/constructed.py
515 516 517 518 | |
FeatureConstruction
Manages a collection of feature engineering objects (subclasses of FeatureBase). Provides methods to process a DataFrame to generate all registered features, and to save/load the feature engineering pipeline configuration.
Source code in physXAI/preprocessing/constructed.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
Attributes
features = list[FeatureBase]()
class-attribute
instance-attribute
Functions
reset()
staticmethod
Clears all registered features and input names.
Source code in physXAI/preprocessing/constructed.py
530 531 532 533 | |
append(f: FeatureBase)
staticmethod
Adds a feature object to the list of managed features. Called automatically from FeatureBase.init.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
FeatureBase
|
The feature object to add. |
required |
Source code in physXAI/preprocessing/constructed.py
535 536 537 538 539 540 541 542 543 544 545 | |
get_feature(name: str) -> Union[FeatureBase, None]
staticmethod
Retrieves a feature object by its name from the managed list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the feature to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Union[FeatureBase, None]
|
FeatureBase or None: The found feature object, or None if not found. |
Source code in physXAI/preprocessing/constructed.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
process(df: DataFrame)
staticmethod
Processes the input DataFrame by applying all registered feature transformations in order.
Each feature's process method is called, which typically adds a new column to df
if it doesn't already exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame to process and add features to. |
required |
Source code in physXAI/preprocessing/constructed.py
563 564 565 566 567 568 569 570 571 572 573 574 575 | |
get_config() -> list
staticmethod
Returns a list of configuration dictionaries for all managed features. This list can be serialized (e.g., to JSON) to save the feature pipeline.
Source code in physXAI/preprocessing/constructed.py
577 578 579 580 581 582 583 584 585 | |
from_config(config: list)
staticmethod
Reconstructs the feature engineering pipeline from a list of configuration dictionaries.
Clears any existing features and populates FeatureConstruction.features with
newly created feature objects based on the provided configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
List[dict]
|
A list where each dictionary is the configuration for a single feature object. |
required |
Source code in physXAI/preprocessing/constructed.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
Functions
register_feature(cls)
A class decorator that registers the decorated class in the CONSTRUCTED_CLASS_REGISTRY. The class is registered using its name.
Source code in physXAI/preprocessing/constructed.py
133 134 135 136 137 138 139 140 141 | |
feature_from_config(item_conf: dict) -> FeatureBase
Factory function to create a feature object from its configuration dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_conf
|
dict
|
The configuration dictionary for a single feature. Must contain 'class_name' and other necessary parameters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FeatureBase |
FeatureBase
|
An instance of the appropriate feature subclass. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If 'class_name' is not in |
Source code in physXAI/preprocessing/constructed.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |