msmbuilder.cluster.LandmarkAgglomerative¶
-
class
msmbuilder.cluster.
LandmarkAgglomerative
(n_clusters, n_landmarks=None, linkage='average', metric='euclidean', landmark_strategy='stride', random_state=None, max_landmarks=None, ward_predictor='ward')¶ Landmark-based agglomerative hierarchical clustering
Landmark-based agglomerative clustering is a simple scalable version of “standard” hierarchical clustering which doesn’t require computing the full matrix of pairwise distances between all data points. The idea is basically to subsample only
n_landmarks
“landmark” data points, cluster them, and then assign labels to the remaining data points based on their distances to (and the labels of) the landmarks.Parameters: - n_clusters : int
The number of clusters to find.
- n_landmarks : int, optional
Memory-saving approximation. Instead of actually clustering every point, we instead select n_landmark points either randomly or by striding the data matrix (see
landmark_strategy
). Then we cluster the only the landmarks, and then assign the remaining dataset based on distances to the landmarks. Note that n_landmarks=None is equivalent to using every point in the dataset as a landmark.- linkage : {‘single’, ‘complete’, ‘average’, ‘ward’}, default=’average’
Which linkage criterion to use. The linkage criterion determines which distance to use between sets of observation. The algorithm will merge the pairs of cluster that minimize this criterion.
- average uses the average of the distances of each observation of the two sets.
- complete or maximum linkage uses the maximum distances between all observations of the two sets.
- single uses the minimum distance between all observations of the two sets.
- ward linkage minimizes the within-cluster variance
The linkage also effects the predict() method and the use of landmarks. After computing the distance from each new data point to the landmarks, the new data point will be assigned to the cluster that minimizes the linkage function between the new data point and each of the landmarks. (i.e with
single
, new data points will be assigned the label of the closest landmark, withaverage
, it will be assigned the label of the landmark s.t. the mean distance from the test point to all the landmarks with that label is minimized, etc.)- metric : string or callable, default= “euclidean”
Metric used to compute the distance between samples.
- landmark_strategy : {‘stride’, ‘random’}, default=’stride’
Method for determining landmark points. Only matters when n_landmarks is not None. “stride” takes landmarks every n-th data point in X, and random selects them uniformly at random.
- random_state : integer or numpy.RandomState, optional
The generator used to select random landmarks. Only used if landmark_strategy==’random’. If an integer is given, it fixes the seed. Defaults to the global numpy random number generator.
- max_landmarks : int, optional, default=None
Useful for hyperparameter searching. If n_clusters exceeds n_landmarks, max_landmarks will be used. Otherwise, n_landmarks will be used. If None, no cutoff is enforced on n_landmarks, which may result in memory issues.
- ward_predictor : {‘single’, ‘complete’, ‘average’, ‘ward’}, default=’ward’
Which criterion to use when predicting cluster assignments after fitting with ward linkage.
References
[1] Mullner, D. “Modern hierarchical, agglomerative clustering algorithms.” arXiv:1109.2378 (2011). Attributes: - landmark_labels_ : np.array, [n_landmarks]
- landmarks_ : np.array, [n_landmarks, X.shape]
- cluster_centers_ : np.array, [n_clusters, X.shape]
Coordinates of cluster centers (unless RMSD is the metric)
Methods
fit
(sequences[, y])Fit the clustering on the data fit_predict
(sequences[, y])Performs clustering on X and returns cluster labels. fit_transform
(sequences[, y])Alias for fit_predict get_params
([deep])Get parameters for this estimator. partial_predict
(X[, y])Predict the closest cluster each sample in X belongs to. partial_transform
(X)Alias for partial_predict predict
(sequences[, y])Predict the closest cluster each sample in each sequence in sequences belongs to. set_params
(**params)Set the parameters of this estimator. summarize
()Return some diagnostic summary statistics about this Markov model transform
(sequences)Alias for predict -
__init__
(n_clusters, n_landmarks=None, linkage='average', metric='euclidean', landmark_strategy='stride', random_state=None, max_landmarks=None, ward_predictor='ward')¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(n_clusters[, n_landmarks, linkage, …])Initialize self. fit
(sequences[, y])Fit the clustering on the data fit_predict
(sequences[, y])Performs clustering on X and returns cluster labels. fit_transform
(sequences[, y])Alias for fit_predict get_params
([deep])Get parameters for this estimator. partial_predict
(X[, y])Predict the closest cluster each sample in X belongs to. partial_transform
(X)Alias for partial_predict predict
(sequences[, y])Predict the closest cluster each sample in each sequence in sequences belongs to. set_params
(**params)Set the parameters of this estimator. summarize
()Return some diagnostic summary statistics about this Markov model transform
(sequences)Alias for predict -
fit
(sequences, y=None)¶ Fit the clustering on the data
Parameters: - sequences : list of array-like, each of shape [sequence_length, n_features]
A list of multivariate timeseries. Each sequence may have a different length, but they all must have the same number of features.
Returns: - self
-
fit_predict
(sequences, y=None)¶ Performs clustering on X and returns cluster labels.
Parameters: - sequences : list of array-like, each of shape [sequence_length, n_features]
A list of multivariate timeseries. Each sequence may have a different length, but they all must have the same number of features.
Returns: - Y : list of ndarray, each of shape [sequence_length, ]
Cluster labels
-
fit_transform
(sequences, y=None)¶ Alias for fit_predict
-
get_params
(deep=True)¶ Get parameters for this estimator.
Parameters: - deep : boolean, optional
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns: - params : mapping of string to any
Parameter names mapped to their values.
-
partial_predict
(X, y=None)¶ Predict the closest cluster each sample in X belongs to.
In the vector quantization literature, cluster_centers_ is called the code book and each value returned by predict is the index of the closest code in the code book.
Parameters: - X : array-like shape=(n_samples, n_features)
A single timeseries.
Returns: - Y : array, shape=(n_samples,)
Index of the cluster that each sample belongs to
-
partial_transform
(X)¶ Alias for partial_predict
-
predict
(sequences, y=None)¶ Predict the closest cluster each sample in each sequence in sequences belongs to.
In the vector quantization literature, cluster_centers_ is called the code book and each value returned by predict is the index of the closest code in the code book.
Parameters: - sequences : list of array-like, each of shape [sequence_length, n_features]
A list of multivariate timeseries. Each sequence may have a different length, but they all must have the same number of features.
Returns: - Y : list of arrays, each of shape [sequence_length,]
Index of the closest center each sample belongs to.
-
set_params
(**params)¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form
<component>__<parameter>
so that it’s possible to update each component of a nested object.Returns: - self
-
summarize
()¶ Return some diagnostic summary statistics about this Markov model
-
transform
(sequences)¶ Alias for predict