koshClustering
KoshCluster
Bases: KoshOperator
Clusters together similar samples from a dataset, and then returns cluster representatives to form a non-redundant subsample of the original dataset. The datasets need to be of shape (n_samples, n_features). All datasets must have the same number of features. If the datasets are more than two dimensions there is an option to flatten them.
Source code in kosh/operators/koshClustering.py
4 5 6 7 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 | |
__init__(*args, **options)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
kosh datasets
|
One or more arrays of size (n_samples, n_features). datasets must have same number of n_features. |
required |
flatten
|
bool
|
Flattens data to two dimensions. (n_samples, n_features_1n_features_2 ... *n_features_m) |
required |
distance_function
|
string | user defined function
|
distance metric 'euclidean', 'seuclidean', 'sqeuclidean', 'beuclidean', or user defined function. Defaults to 'euclidean' |
required |
scaling_function
|
string | user defined function
|
Scaling function to use on data before it is clustered. |
required |
batch
|
bool
|
Whether to cluster data in batches |
required |
batch_size
|
int
|
Size of the batches |
required |
gather_to
|
Which process to gather data to if samples are smaller than number of processes or batch size. type gather_to: int |
required | |
convergence_num
|
int | float between 0 and 1
|
If int, converged after the data size is the same for 'num' iterations. The default is 2. If float, converged after the change in data size is less than convergence_num*100 percent of the original data size. |
required |
core_sample
|
bool
|
Whether to retain a sample from the center of the cluster (core sample), or a randomly chosen sample. |
required |
eps
|
float
|
The distance around a sample that defines its neighbors. |
required |
auto_eps
|
bool
|
Use the algorithm to find the epsilon distance for clustering based on the desired information loss. |
required |
eps_0
|
float
|
The initial epsilon guess for the auto eps algorithm. |
required |
min_samples
|
int
|
The minimum number of samples to form a cluster. |
required |
target_loss
|
float
|
The proportion of information loss allowed from removing samples from the original dataset. The default is .01 or 1% loss. |
required |
non_dim_return
|
bool
|
The option to return non-dimensional information loss. |
required |
data_source
|
int
|
The rank the kosh operator will obtain the dataset from. -1 is the default and all ranks will provide the datasets, a positive int will indicate data is read in from a specific rank. |
required |
verbose
|
bool
|
Verbose message |
required |
output
|
string
|
The retained data or the indices to get the retained data from the original dataset. |
required |
format
|
string
|
Returns the indices as numpy array ('numpy') or defaults to pandas dataframe. |
required |
Returns:
| Type | Description |
|---|---|
list with elements in the list being either numpy array | pandas dataframe
|
A list containing: 1. The reduced dataset or indices to reduce the original dataset. 2. The estimated information loss or if using the auto eps algorithm (eps=-1) the second item in the list will be the epsilon value found with auto eps. |
Source code in kosh/operators/koshClustering.py
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 | |
operate(*inputs, **kargs)
Checks for serial or parallel clustering and calls those functions
Source code in kosh/operators/koshClustering.py
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 | |
KoshClusterLossPlot
Bases: KoshOperator
Calculates sample size and estimated information loss for a range of distance values.
Source code in kosh/operators/koshClustering.py
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 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 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 | |
__init__(*args, **options)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
kosh datasets
|
One or more arrays of size (n_samples, n_features). Datasets must have same number of n_features. |
required |
method
|
string
|
DBSCAN, HDBSCAN, or HAC (Hierarchical Agglomerative Clustering) |
required |
flatten
|
bool
|
Flattens data to two dimensions. (n_samples, n_features_1n_features_2 ... *n_features_m) |
required |
val_range
|
array
|
Range of distance values to use for clustering/subsampling |
required |
val_type
|
string
|
Choose the type of value range for clustering: raw distance ('raw'), scaled distance ('scaled'), or number of clusters ('Nclusters'). |
required |
scaling_function
|
string | user defined function
|
Scaling function to use on data before it is clustered. |
required |
distance_function
|
string, | callable
|
A valid pairwise distance option from scipy.spatial.distance, or a user defined distance function. |
required |
batch
|
bool
|
Whether to cluster data in batches |
required |
batch_size
|
int
|
Size of the batches |
required |
gather_to
|
Which process to gather data to if samples are smaller than number of processes or batch size. type gather_to: int |
required | |
convergence_num
|
int | float between 0 and 1
|
If int, converged after the data size is the same for 'num' iterations. The default is 2. If float, converged after the change in data size is less than convergence_num*100 percent of the original data size. |
required |
non_dim_return
|
bool
|
The option to return non-dimensional information loss. |
required |
data_source
|
int
|
The ranks the kosh operator will obtain the dataset from. -1 is the default and all ranks will provide the datasets, a positive int will indicate data is read in from a specific rank. |
required |
verbose
|
bool
|
Verbose message |
required |
draw_plot
|
bool | matplotlib.pyplot.Axes object
|
Whether to plot the plt object. otherwise it returns a list of three arrays: the distance value range, loss estimate, and sample size. You can pass a matplotlib Axes instance if desired. |
required |
fileNameTemplate
|
string
|
The name to save the plot object |
required |
outputFormat
|
string
|
Returns the information as matplotlib pyplot object ('mpl'), png file ('png'), or numpy array ('numpy') |
required |
min_samples
|
int
|
The minimum number of samples to form a cluster. (Only for DBSCAN) |
required |
n_jobs
|
int
|
The number of parallel jobs to run. -1 means using all processors. |
required |
Returns:
| Type | Description |
|---|---|
object, string, array
|
plt object showing loss/sample size information, location of the saved file, or an array with val_range, loss estimate, and sample size |
Source code in kosh/operators/koshClustering.py
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 | |
operate(*inputs, **kargs)
Calculates sample size and estimated information loss for a range of distance values.
Source code in kosh/operators/koshClustering.py
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 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 | |
KoshHopkins
Bases: KoshOperator
Calculates the Hopkins statistic or cluster tendency of the data
Source code in kosh/operators/koshClustering.py
__init__(*args, **options)
from a sample of the dataset. A value close to 0 means uniformly distributed, .5 means randomly distributed, and a value close to 1 means highly clustered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
kosh datasets
|
One or more arrays of size (n_samples, n_features). Datasets must have same number of n_features. |
required |
sample_ratio
|
float, between zero and one
|
Proportion of data for sample |
required |
scaling_function
|
string | user defined function
|
Scaling function to use on data before it is clustered. |
required |
flatten
|
bool
|
Flattens data to two dimensions. (n_samples, n_features_1n_features_2 ... *n_features_m) |
required |
Returns:
| Type | Description |
|---|---|
float
|
Hopkins statistic |