getml.pipeline.Features
Container which holds a pipeline's features. Features can be accessed by name, index or with a numpy array. The container supports slicing and is sort- and filterable.
Further, the container holds global methods to request features' importances, correlations and their respective transpiled sql representation.
PARAMETER | DESCRIPTION |
---|---|
pipeline |
The name of the pipeline the features are associated with.
TYPE:
|
targets |
The targets the features are associated with. |
data |
The features to be stored in the container. |
Note
The container is an iterable. So, in addition to
filter
you can also use python list
comprehensions for filtering.
Example
all_my_features = my_pipeline.features
first_feature = my_pipeline.features[0]
second_feature = my_pipeline.features["feature_1_2"]
all_but_last_10_features = my_pipeline.features[:-10]
important_features = [feature for feature in my_pipeline.features if feature.importance > 0.1]
names, importances = my_pipeline.features.importances()
names, correlations = my_pipeline.features.correlations()
sql_code = my_pipeline.features.to_sql()
Source code in getml/pipeline/features.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
correlation
property
importance
property
name
property
names
property
correlations
Returns the data for the feature correlations, as displayed in the getML Monitor.
PARAMETER | DESCRIPTION |
---|---|
target_num |
Indicates for which target you want to view the importances. (Pipelines can have more than one target.)
TYPE:
|
sort |
Whether you want the results to be sorted.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray[str_]
|
The first array contains the names of the features. |
NDArray[float_]
|
The second array contains the correlations with the target. |
Source code in getml/pipeline/features.py
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 |
|
filter
Filters the Features container.
PARAMETER | DESCRIPTION |
---|---|
conditional |
A callable that evaluates to a boolean for a given item. |
RETURNS | DESCRIPTION |
---|---|
Features
|
A container of filtered Features. |
Example
important_features = my_pipeline.features.filter(lambda feature: feature.importance > 0.1)
correlated_features = my_pipeline.features.filter(lambda feature: feature.correlation > 0.3)
Source code in getml/pipeline/features.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
importances
Returns the data for the feature importances, as displayed in the getML Monitor.
PARAMETER | DESCRIPTION |
---|---|
target_num |
Indicates for which target you want to view the importances. (Pipelines can have more than one target.)
TYPE:
|
sort |
Whether you want the results to be sorted.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray[str_]
|
The first array contains the names of the features. |
NDArray[float_]
|
The second array contains their importances. By definition, all importances add up to 1. |
Source code in getml/pipeline/features.py
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 |
|
sort
sort(
by: Optional[str] = None,
key: Optional[
Callable[[Feature], Union[float, int, str]]
] = None,
descending: Optional[bool] = None,
) -> Features
Sorts the Features container. If no arguments are provided the container is sorted by target and name.
PARAMETER | DESCRIPTION |
---|---|
by |
The name of field to sort by. Possible fields: - name(s) - correlation(s) - importances(s) |
key |
A callable that evaluates to a sort key for a given item.
TYPE:
|
descending |
Whether to sort in descending order. |
RETURNS | DESCRIPTION |
---|---|
Features
|
A container of sorted Features. |
Example
by_correlation = my_pipeline.features.sort(by="correlation")
by_importance = my_pipeline.features.sort(key=lambda feature: feature.importance)
Source code in getml/pipeline/features.py
463 464 465 466 467 468 469 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 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 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 |
|
to_pandas
to_pandas() -> DataFrame
Returns all information related to the features in a pandas data frame.
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
A pandas data frame containing the features' names, importances, correlations, and SQL code. |
Source code in getml/pipeline/features.py
549 550 551 552 553 554 555 556 557 |
|
to_sql
to_sql(
targets: bool = True,
subfeatures: bool = True,
dialect: str = sqlite3,
schema: Optional[str] = None,
nchar_categorical: int = 128,
nchar_join_key: int = 128,
nchar_text: int = 4096,
size_threshold: Optional[int] = 50000,
) -> SQLCode
Returns SQL statements visualizing the features.
PARAMETER | DESCRIPTION |
---|---|
targets |
Whether you want to include the target columns in the main table.
TYPE:
|
subfeatures |
Whether you want to include the code for the subfeatures of a snowflake schema.
TYPE:
|
dialect |
The SQL dialect to use. Must be from
|
schema |
The schema in which to wrap all generated tables and indices. None for no schema. Not applicable to all dialects. For the BigQuery and MySQL dialects, the schema is identical to the database ID. |
nchar_categorical |
The maximum number of characters used in the VARCHAR for categorical columns. Not applicable to all dialects.
TYPE:
|
nchar_join_key |
The maximum number of characters used in the VARCHAR for join keys. Not applicable to all dialects.
TYPE:
|
nchar_text |
The maximum number of characters used in the VARCHAR for text columns. Not applicable to all dialects.
TYPE:
|
size_threshold |
The maximum number of characters to display in a single feature. Displaying extremely complicated features can crash your iPython notebook or lead to unexpectedly high memory consumption, which is why a reasonable upper limit is advantageous. Set to None for no upper limit. |
RETURNS | DESCRIPTION |
---|---|
SQLCode
|
Object representing the features. |
Example
my_pipeline.features.to_sql()
Note
Only fitted pipelines
(fit
) can hold trained
features which can be returned as SQL statements.
Note
The getML Community edition only supports transpilation to human-readable SQL. Passing 'sqlite3' will also produce human-readable SQL.
Source code in getml/pipeline/features.py
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 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
|