snowflake.ml.modeling.cluster.OPTICSΒΆ
- class snowflake.ml.modeling.cluster.OPTICS(*, min_samples=5, max_eps=inf, metric='minkowski', p=2, metric_params=None, cluster_method='xi', eps=None, xi=0.05, predecessor_correction=True, min_cluster_size=None, algorithm='auto', leaf_size=30, memory=None, n_jobs=None, input_cols: Optional[Union[str, Iterable[str]]] = None, output_cols: Optional[Union[str, Iterable[str]]] = None, label_cols: Optional[Union[str, Iterable[str]]] = None, drop_input_cols: Optional[bool] = False, sample_weight_col: Optional[str] = None)ΒΆ
Bases:
BaseTransformer
Estimate clustering structure from vector array For more details on this class, see sklearn.cluster.OPTICS
- min_samples: int > 1 or float between 0 and 1, default=5
The number of samples in a neighborhood for a point to be considered as a core point. Also, up and down steep regions canβt have more than
min_samples
consecutive non-steep points. Expressed as an absolute number or a fraction of the number of samples (rounded to be at least 2).- max_eps: float, default=np.inf
The maximum distance between two samples for one to be considered as in the neighborhood of the other. Default value of
np.inf
will identify clusters across all scales; reducingmax_eps
will result in shorter run times.- metric: str or callable, default=βminkowskiβ
Metric to use for distance computation. Any metric from scikit-learn or scipy.spatial.distance can be used.
If metric is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two arrays as input and return one value indicating the distance between them. This works for Scipyβs metrics, but is less efficient than passing the metric name as a string. If metric is βprecomputedβ, X is assumed to be a distance matrix and must be square.
Valid values for metric are:
from scikit-learn: [βcityblockβ, βcosineβ, βeuclideanβ, βl1β, βl2β, βmanhattanβ]
from scipy.spatial.distance: [βbraycurtisβ, βcanberraβ, βchebyshevβ, βcorrelationβ, βdiceβ, βhammingβ, βjaccardβ, βkulsinskiβ, βmahalanobisβ, βminkowskiβ, βrogerstanimotoβ, βrussellraoβ, βseuclideanβ, βsokalmichenerβ, βsokalsneathβ, βsqeuclideanβ, βyuleβ]
Sparse matrices are only supported by scikit-learn metrics. See the documentation for scipy.spatial.distance for details on these metrics.
- p: float, default=2
Parameter for the Minkowski metric from
pairwise_distances
. When p = 1, this is equivalent to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.- metric_params: dict, default=None
Additional keyword arguments for the metric function.
- cluster_method: str, default=βxiβ
The extraction method used to extract clusters using the calculated reachability and ordering. Possible values are βxiβ and βdbscanβ.
- eps: float, default=None
The maximum distance between two samples for one to be considered as in the neighborhood of the other. By default it assumes the same value as
max_eps
. Used only whencluster_method='dbscan'
.- xi: float between 0 and 1, default=0.05
Determines the minimum steepness on the reachability plot that constitutes a cluster boundary. For example, an upwards point in the reachability plot is defined by the ratio from one point to its successor being at most 1-xi. Used only when
cluster_method='xi'
.- predecessor_correction: bool, default=True
Correct clusters according to the predecessors calculated by OPTICS [2]_. This parameter has minimal effect on most datasets. Used only when
cluster_method='xi'
.- min_cluster_size: int > 1 or float between 0 and 1, default=None
Minimum number of samples in an OPTICS cluster, expressed as an absolute number or a fraction of the number of samples (rounded to be at least 2). If
None
, the value ofmin_samples
is used instead. Used only whencluster_method='xi'
.- algorithm: {βautoβ, βball_treeβ, βkd_treeβ, βbruteβ}, default=βautoβ
Algorithm used to compute the nearest neighbors:
βball_treeβ will use
BallTree
.βkd_treeβ will use
KDTree
.βbruteβ will use a brute-force search.
βautoβ (default) will attempt to decide the most appropriate algorithm based on the values passed to
fit()
method.
Note: fitting on sparse input will override the setting of this parameter, using brute force.
- leaf_size: int, default=30
Leaf size passed to
BallTree
orKDTree
. This can affect the speed of the construction and query, as well as the memory required to store the tree. The optimal value depends on the nature of the problem.- memory: str or object with the joblib.Memory interface, default=None
Used to cache the output of the computation of the tree. By default, no caching is done. If a string is given, it is the path to the caching directory.
- n_jobs: int, default=None
The number of parallel jobs to run for neighbors search.
None
means 1 unless in ajoblib.parallel_backend
context.-1
means using all processors. See Glossary for more details.- input_cols: Optional[Union[str, List[str]]]
A string or list of strings representing column names that contain features. If this parameter is not specified, all columns in the input DataFrame except the columns specified by label_cols and sample-weight_col parameters are considered input columns.
- label_cols: Optional[Union[str, List[str]]]
A string or list of strings representing column names that contain labels. This is a required param for estimators, as there is no way to infer these columns. If this parameter is not specified, then object is fitted without labels(Like a transformer).
- output_cols: Optional[Union[str, List[str]]]
A string or list of strings representing column names that will store the output of predict and transform operations. The length of output_cols mus match the expected number of output columns from the specific estimator or transformer class used. If this parameter is not specified, output column names are derived by adding an OUTPUT_ prefix to the label column names. These inferred output column names work for estimatorβs predict() method, but output_cols must be set explicitly for transformers.
- sample_weight_col: Optional[str]
A string representing the column name containing the examplesβ weights. This argument is only required when working with weighted datasets.
- drop_input_cols: Optional[bool], default=False
If set, the response of predict(), transform() methods will not contain input columns.
Methods
fit
(dataset)Perform OPTICS clustering For more details on this function, see sklearn.cluster.OPTICS.fit
score
(dataset)Method not supported for this class.
set_input_cols
(input_cols)Input columns setter.
to_sklearn
()Get sklearn.cluster.OPTICS object.
Attributes
model_signatures
Returns model signature of current class.