incremental_feature_clustering
Bases: feature_selection
Incremental feature selection and clustering using Spectral Clustering.
This class clusters features into a specified number of clusters using Spectral Clustering based on a similarity matrix derived from the input data. It supports incremental updates to the similarity matrix.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the feature clustering method. |
random_state |
int
|
Random state for reproducibility of the Spectral Clustering model. |
feature_clustering_model |
SpectralClustering
|
The Spectral Clustering model for clustering features. |
D |
Tensor or None
|
The accumulated similarity matrix. |
t |
int or None
|
The iteration count for incremental updates. |
Methods:
Name | Description |
---|---|
update_n_feature |
Update the number of feature clusters. |
update_D |
Update the similarity matrix incrementally or replace it with a new matrix. |
fit |
Fit the clustering model to the input data. |
compute_centroids |
Compute centroids for each cluster. |
transform |
Transform the input data to reduced features using the clustering model. |
Source code in tinybig/koala/machine_learning/feature_selection/incremental_feature_clustering.py
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 |
|
__init__(name='incremental_variance_threshold', random_state=42, *args, **kwargs)
Initialize the incremental feature clustering class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the feature clustering method. Default is 'incremental_variance_threshold'. |
'incremental_variance_threshold'
|
random_state
|
int
|
Random state for reproducibility. Default is 42. |
42
|
*args
|
Additional arguments for the base class. |
()
|
|
**kwargs
|
Additional arguments for the base class. |
()
|
Source code in tinybig/koala/machine_learning/feature_selection/incremental_feature_clustering.py
compute_centroids(X, labels, n_clusters)
Compute centroids for each cluster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
Union[ndarray, Tensor]
|
The input data. |
required |
labels
|
array
|
The cluster labels for each feature. |
required |
n_clusters
|
int
|
The number of clusters. |
required |
Returns:
Type | Description |
---|---|
Union[ndarray, Tensor]
|
The centroids of the clusters. |
Source code in tinybig/koala/machine_learning/feature_selection/incremental_feature_clustering.py
fit(X, device='cpu', *args, **kwargs)
Fit the clustering model to the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
Union[ndarray, Tensor]
|
The input data for fitting. |
required |
device
|
str
|
The device to use for computation ('cpu' or 'cuda'). Default is 'cpu'. |
'cpu'
|
*args
|
Additional arguments for the clustering process. |
()
|
|
**kwargs
|
Additional arguments for the clustering process. |
()
|
Source code in tinybig/koala/machine_learning/feature_selection/incremental_feature_clustering.py
transform(X, device='cpu', *args, **kwargs)
Transform the input data to reduced features using the clustering model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
Union[ndarray, Tensor]
|
The input data. |
required |
device
|
str
|
The device to use for computation ('cpu' or 'cuda'). Default is 'cpu'. |
'cpu'
|
*args
|
Additional arguments for the transformation process. |
()
|
|
**kwargs
|
Additional arguments for the transformation process. |
()
|
Returns:
Type | Description |
---|---|
Union[ndarray, Tensor]
|
The reduced features after clustering. |
Source code in tinybig/koala/machine_learning/feature_selection/incremental_feature_clustering.py
update_D(new_D)
Update the similarity matrix incrementally or replace it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_D
|
Tensor
|
The new similarity matrix to update or replace the existing one. |
required |
Source code in tinybig/koala/machine_learning/feature_selection/incremental_feature_clustering.py
update_n_feature(new_n_feature)
Update the number of feature clusters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_n_feature
|
int
|
The new number of feature clusters. |
required |