Outliers¶
outliers ¶
Assembly: mathy Filename: outliers.py Author: Terry D. Eppler Created: 05-31-2022
Last Modified By: Terry D. Eppler Last Modified On: 05-01-2025
outliers.py
Copyright © 2022 Terry Eppler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You can contact me at: terryeppler@gmail.com or eppler.terry@epa.gov
Purpose
Supports unsupervised anomaly detection workflows by standardizing input validation, model fitting, inlier/outlier prediction, anomaly-score extraction, aggregate-count calculation, and compact visualization of detection results. The wrappers expose consistent attributes for predictions, anomaly scores, inlier counts, and outlier counts so downstream notebooks, dashboards, and documentation can consume estimator outputs without estimator-specific code.
Notes
Prediction labels follow the sklearn anomaly-detection convention where 1 represents an
inlier and -1 represents an outlier.
Outlier ¶
Outlier-analysis interface.
Purpose
Establishes the common contract implemented by anomaly-detection wrappers in this module. The interface defines shared runtime attributes for predictions, anomaly scores, inlier counts, and outlier counts while requiring concrete estimators to provide training, projection, scoring, and analysis behavior.
Attributes:
| Name | Type | Description |
|---|---|---|
prediction |
Optional[ndarray]
|
Most recent inlier/outlier prediction vector. |
probability |
Optional[ndarray]
|
Optional probability output retained for interface compatibility. |
decision |
Optional[ndarray]
|
Optional decision-function output retained for interface compatibility. |
max_depth |
Optional[int]
|
Optional model-depth metadata retained for interface compatibility. |
random_state |
Optional[int]
|
Optional random-state metadata retained for interface compatibility. |
anomaly_scores |
Optional[float]
|
Most recent anomaly-score output or summary value. |
learning_rate |
Optional[float]
|
Optional learning-rate metadata retained for interface compatibility. |
outliers |
Optional[float]
|
Count of samples predicted as outliers. |
inliers |
Optional[float]
|
Count of samples predicted as inliers. |
Source code in outliers.py
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 | |
train ¶
Fit an outlier detector.
Purpose
Defines the required training contract for concrete anomaly-detection wrappers. Implementations must fit the wrapped estimator to a feature matrix and return the fitted class/object when training completes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to fit the detector. |
required |
y
|
ndarray
|
Optional target vector accepted for interface consistency. |
required |
Returns:
| Type | Description |
|---|---|
object | None
|
object | None: Fitted concrete detector class/object. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raised when the base interface method is called directly. |
Source code in outliers.py
project ¶
Predict inliers and outliers.
Purpose
Defines the required projection contract for concrete anomaly-detection wrappers. Implementations must return a vector of inlier and outlier labels for the supplied samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to generate predictions. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Prediction vector where |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raised when the base interface method is called directly. |
Source code in outliers.py
score ¶
Score anomaly predictions.
Purpose
Defines the required scoring contract for concrete anomaly-detection wrappers. Implementations must return estimator-specific score output suitable for per-sample review or model diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to compute anomaly scores. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Estimator-specific anomaly score output. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raised when the base interface method is called directly. |
Source code in outliers.py
analyze ¶
Analyze anomaly results.
Purpose
Defines the required analysis contract for concrete anomaly-detection wrappers. Implementations must summarize inlier and outlier counts, calculate quality or contamination metrics, and return a compact analysis object for downstream reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to generate the analysis. |
required |
y
|
ndarray
|
Optional target vector accepted for interface consistency. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, float] | None
|
Dict[str, float] | None: Dictionary or dataframe containing aggregate anomaly-detection metrics. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raised when the base interface method is called directly. |
Source code in outliers.py
IsolationForest ¶
Bases: Outlier
Provides IsolationForest model functionality.
Purpose
Detects anomalies by fitting an ensemble of randomized isolation trees and identifying samples that require fewer splits to isolate. The class/object stores the fitted estimator, contamination setting, prediction vector, anomaly scores, and aggregate inlier/outlier counts for consistent downstream analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
IsolationForest
|
Underlying isolation-forest estimator. |
contamination |
float
|
Expected proportion of outliers in the input data. |
prediction |
Optional[ndarray]
|
Most recent inlier/outlier prediction vector. |
anomaly_scores |
Optional[ndarray]
|
Most recent isolation-forest decision scores. |
Source code in outliers.py
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 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 | |
train ¶
Fit the IsolationForest detector.
Purpose
Validates the supplied feature matrix, fits the underlying IsolationForest estimator, refreshes prediction and anomaly-score state when the estimator exposes training-set predictions, and updates aggregate inlier and outlier counts for downstream scoring and reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to fit the anomaly-detection estimator. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
IsolationForest | None
|
IsolationForest | None: Fitted IsolationForest class/object instance. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation or estimator fitting fails. |
Source code in outliers.py
project ¶
Predict with the IsolationForest detector.
Purpose
Validates the supplied feature matrix and generates inlier/outlier labels with the fitted IsolationForest estimator. The prediction vector is cached on the class/object for later scoring, analysis, and inspection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to generate inlier and outlier predictions. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray | None
|
np.ndarray | None: Prediction vector where |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation or estimator prediction fails. |
Source code in outliers.py
score ¶
Create per-sample IsolationForest scores.
Purpose
Validates the supplied feature matrix, generates or refreshes inlier/outlier predictions, computes estimator-specific anomaly scores, updates aggregate inlier and outlier counts, and returns a dataframe containing prediction, anomaly, inlier, and outlier columns for sample-level review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to compute predictions and anomaly scores. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame | None: Dataframe containing per-sample predictions, anomaly scores, inlier flags, and outlier flags. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation, prediction, score calculation, or dataframe construction fails. |
Source code in outliers.py
analyze ¶
Summarize IsolationForest anomaly results.
Purpose
Validates the supplied feature matrix, builds per-sample score output, creates aggregate inlier, outlier, contamination, and quality metrics where supported, renders an inlier-versus-outlier bar chart, and returns the summary dataframe for reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to compute anomaly-analysis output. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame | None: Summary dataframe containing aggregate anomaly-detection metrics. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation, scoring, summary construction, or chart rendering fails. |
Source code in outliers.py
OneClass ¶
Bases: Outlier
One-Class Support Vector Machine.
Purpose
Detects novelty and outliers by learning the support of the normal data distribution with a one-class support-vector machine. The class/object stores kernel configuration, the fitted estimator, prediction labels, anomaly scores, and aggregate inlier/outlier counts for consistent reporting.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
Optional[OneClassSVM]
|
Underlying One-Class SVM estimator. |
data |
Optional[ndarray]
|
Optional fitted-data cache retained for interface compatibility. |
prediction |
Optional[ndarray]
|
Most recent inlier/outlier prediction vector. |
anomaly_scores |
Optional[ndarray]
|
Most recent One-Class SVM decision scores. |
kernel |
Optional[str]
|
Kernel used by the underlying One-Class SVM estimator. |
Source code in outliers.py
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 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 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 604 605 606 607 608 609 610 | |
train ¶
Fit the One-Class SVM detector.
Purpose
Validates the supplied feature matrix, fits the underlying One-Class SVM estimator, refreshes prediction and anomaly-score state when the estimator exposes training-set predictions, and updates aggregate inlier and outlier counts for downstream scoring and reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to fit the anomaly-detection estimator. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
OneClass | None
|
OneClass | None: Fitted OneClass class/object instance. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation or estimator fitting fails. |
Source code in outliers.py
project ¶
Predict with the One-Class SVM detector.
Purpose
Validates the supplied feature matrix and generates inlier/outlier labels with the fitted One-Class SVM estimator. The prediction vector is cached on the class/object for later scoring, analysis, and inspection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to generate inlier and outlier predictions. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray | None
|
np.ndarray | None: Prediction vector where |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation or estimator prediction fails. |
Source code in outliers.py
score ¶
Create per-sample One-Class SVM scores.
Purpose
Validates the supplied feature matrix, generates or refreshes inlier/outlier predictions, computes estimator-specific anomaly scores, updates aggregate inlier and outlier counts, and returns a dataframe containing prediction, anomaly, inlier, and outlier columns for sample-level review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to compute predictions and anomaly scores. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame | None: Dataframe containing per-sample predictions, anomaly scores, inlier flags, and outlier flags. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation, prediction, score calculation, or dataframe construction fails. |
Source code in outliers.py
analyze ¶
Summarize One-Class SVM anomaly results.
Purpose
Validates the supplied feature matrix, builds per-sample score output, creates aggregate inlier, outlier, contamination, and quality metrics where supported, renders an inlier-versus-outlier bar chart, and returns the summary dataframe for reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to compute anomaly-analysis output. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame | None: Summary dataframe containing aggregate anomaly-detection metrics. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation, scoring, summary construction, or chart rendering fails. |
Source code in outliers.py
OutlierFactor ¶
Bases: Outlier
Wrap LocalOutlierFactor.
Purpose
Detects density-based anomalies by comparing each sample's local density with the local density of neighboring samples. The class/object supports both novelty and fit-predict behavior while storing predictions, anomaly scores, neighborhood settings, contamination settings, and aggregate counts.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
LocalOutlierFactor
|
Underlying Local Outlier Factor estimator. |
prediction |
Optional[ndarray]
|
Most recent inlier/outlier prediction vector. |
anomaly_scores |
Optional[ndarray]
|
Most recent local outlier scores or decision scores. |
neighbors |
Optional[int]
|
Number of neighbors used for local density estimation. |
contamination |
Optional[float]
|
Expected proportion of outliers in the data. |
novelty |
Optional[bool]
|
Flag indicating whether novelty detection is enabled. |
Source code in outliers.py
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 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | |
train ¶
Fit the Local Outlier Factor detector.
Purpose
Validates the supplied feature matrix, fits the underlying Local Outlier Factor estimator, refreshes prediction and anomaly-score state when the estimator exposes training-set predictions, and updates aggregate inlier and outlier counts for downstream scoring and reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to fit the anomaly-detection estimator. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
OutlierFactor | None
|
OutlierFactor | None: Fitted OutlierFactor class/object instance. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation or estimator fitting fails. |
Source code in outliers.py
project ¶
Predict with the Local Outlier Factor detector.
Purpose
Validates the supplied feature matrix and generates inlier/outlier labels with the fitted Local Outlier Factor estimator. The prediction vector is cached on the class/object for later scoring, analysis, and inspection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to generate inlier and outlier predictions. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray | None
|
np.ndarray | None: Prediction vector where |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation or estimator prediction fails. |
Source code in outliers.py
score ¶
Create per-sample Local Outlier Factor scores.
Purpose
Validates the supplied feature matrix, generates or refreshes inlier/outlier predictions, computes estimator-specific anomaly scores, updates aggregate inlier and outlier counts, and returns a dataframe containing prediction, anomaly, inlier, and outlier columns for sample-level review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to compute predictions and anomaly scores. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame | None: Dataframe containing per-sample predictions, anomaly scores, inlier flags, and outlier flags. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation, prediction, score calculation, or dataframe construction fails. |
Source code in outliers.py
analyze ¶
Summarize Local Outlier Factor anomaly results.
Purpose
Validates the supplied feature matrix, builds per-sample score output, creates aggregate inlier, outlier, contamination, and quality metrics where supported, renders an inlier-versus-outlier bar chart, and returns the summary dataframe for reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to compute anomaly-analysis output. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame | None: Summary dataframe containing aggregate anomaly-detection metrics. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation, scoring, summary construction, or chart rendering fails. |
Source code in outliers.py
EllipticSquare ¶
Bases: Outlier
Provides the EllipticEnvelope functionality.
Purpose
Detects multivariate outliers by fitting a robust covariance estimate and identifying samples outside the learned elliptical data envelope. The class/object stores the fitted estimator, contamination setting, prediction labels, anomaly scores, and aggregate inlier/outlier counts.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
EllipticEnvelope
|
Underlying robust covariance estimator. |
prediction |
Optional[ndarray]
|
Most recent inlier/outlier prediction vector. |
anomaly_scores |
Optional[ndarray]
|
Most recent EllipticEnvelope decision scores. |
contamination |
Optional[float]
|
Expected proportion of outliers in the input data. |
Source code in outliers.py
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | |
train ¶
Fit the EllipticEnvelope detector.
Purpose
Validates the supplied feature matrix, fits the underlying EllipticEnvelope estimator, refreshes prediction and anomaly-score state when the estimator exposes training-set predictions, and updates aggregate inlier and outlier counts for downstream scoring and reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to fit the anomaly-detection estimator. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
EllipticSquare | None
|
EllipticSquare | None: Fitted EllipticSquare class/object instance. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation or estimator fitting fails. |
Source code in outliers.py
project ¶
Predict with the EllipticEnvelope detector.
Purpose
Validates the supplied feature matrix and generates inlier/outlier labels with the fitted EllipticEnvelope estimator. The prediction vector is cached on the class/object for later scoring, analysis, and inspection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to generate inlier and outlier predictions. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray | None
|
np.ndarray | None: Prediction vector where |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation or estimator prediction fails. |
Source code in outliers.py
score ¶
Create per-sample EllipticEnvelope scores.
Purpose
Validates the supplied feature matrix, generates or refreshes inlier/outlier predictions, computes estimator-specific anomaly scores, updates aggregate inlier and outlier counts, and returns a dataframe containing prediction, anomaly, inlier, and outlier columns for sample-level review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to compute predictions and anomaly scores. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame | None: Dataframe containing per-sample predictions, anomaly scores, inlier flags, and outlier flags. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation, prediction, score calculation, or dataframe construction fails. |
Source code in outliers.py
analyze ¶
Summarize EllipticEnvelope anomaly results.
Purpose
Validates the supplied feature matrix, builds per-sample score output, creates aggregate inlier, outlier, contamination, and quality metrics where supported, renders an inlier-versus-outlier bar chart, and returns the summary dataframe for reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix used to compute anomaly-analysis output. |
required |
y
|
Optional[ndarray]
|
Optional target vector accepted for interface consistency. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame | None: Summary dataframe containing aggregate anomaly-detection metrics. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised when validation, scoring, summary construction, or chart rendering fails. |
Source code in outliers.py
throw_if ¶
Validate a required clustering argument.
Purpose
Enforces the presence of required clustering inputs before estimator execution. The validation accepts populated NumPy arrays and standard Python containers while rejecting null values and empty collections that would otherwise cause downstream operations to fail or produce undefined clustering results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Argument name used in the validation error message. |
required |
value
|
object
|
Argument value checked for a null or empty state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function performs its work through side effects and does not return a value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when |