Optics
Module: optics.py
This module provides an OPTICS (Ordering Points To Identify the Clustering Structure) implementation.
It allows optional user-defined 'min_samples' and 'min_cluster_size', or applies a heuristic approach if they're not provided.
Classes:
Name | Description |
---|---|
Optics |
Implements OPTICS with optional user override or heuristic-based approach. |
Dependencies
- numpy
- sklearn.cluster.OPTICS
- base.py (Clustering)
Key Features
- If user-defined 'min_samples' or 'min_cluster_size' is set, skip auto-heuristic
- Otherwise, compute a simple heuristic
Version Info
- 28/Dec/2024: Initial release
Optics
Bases: Clustering
OPTICS clustering with optional user-defined 'min_samples' and 'min_cluster_size', or a heuristic-based approach if they are not provided.
Attributes:
Name | Type | Description |
---|---|---|
min_samples |
Optional[int]
|
If provided, used directly by OPTICS; otherwise estimated. |
min_cluster_size |
Optional[int]
|
If provided, used directly by OPTICS; otherwise estimated. |
xi |
float
|
Determines the minimum steepness on the reachability plot for cluster extraction. |
labels |
Optional[ndarray]
|
Cluster labels for each data point after fitting (-1 for noise). |
n_clusters_ |
Optional[int]
|
Number of clusters discovered (excluding noise). |
n_noise_ |
Optional[int]
|
Number of data points labeled as noise. |
Source code in scirex/core/ml/unsupervised/clustering/optics.py
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 |
|
__init__(min_samples=None, min_cluster_size=None, xi=0.05)
Initialize the OPTICS clustering model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_samples
|
Optional[int]
|
If provided, the algorithm uses this min_samples. Otherwise, a heuristic is used. |
None
|
min_cluster_size
|
Optional[int]
|
If provided, the algorithm uses this min_cluster_size. Otherwise, a heuristic is used. |
None
|
xi
|
float
|
Determines the minimum steepness on the reachability plot for cluster extraction. Defaults to 0.05. |
0.05
|
Source code in scirex/core/ml/unsupervised/clustering/optics.py
fit(X)
Fit the OPTICS model to the data. - If min_samples/min_cluster_size are not set, estimate them heuristically. - Then create and fit an OPTICS model, storing labels and cluster info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
Input data array of shape (n_samples, n_features). |
required |
Source code in scirex/core/ml/unsupervised/clustering/optics.py
get_model_params()
Retrieve key parameters and results from the fitted OPTICS model.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: - min_samples (int): The final min_samples used - min_cluster_size (int): The final min_cluster_size used - n_clusters (int): Number of clusters discovered (excluding noise) - n_noise (int): Number of data points labeled as noise |