Apply clustering to a projection to the normalized laplacian.
In practice Spectral Clustering is very useful when the structure of the individual clusters is highly non-convex or more generally when a measure of the center and spread of the cluster is not a suitable description of the complete cluster. For instance when clusters are nested circles on the 2D plan.
If affinity is the adjacency matrix of a graph, this method can be used to find normalized graph cuts.
When calling fit, an affinity matrix is constructed using either kernel function such the Gaussian (aka RBF) kernel of the euclidean distanced d(X, X):
np.exp(-gamma * d(X,X) ** 2)
or a k-nearest neighbors connectivity matrix.
Alternatively, using precomputed, a user-provided affinity matrix can be used.
Parameters: | n_clusters : integer, optional
affinity : string, array-like or callable, default ‘rbf’
gamma : float
degree : float, default=3
coef0 : float, default=1
n_neighbors : integer
eigen_solver : {None, ‘arpack’, ‘lobpcg’, or ‘amg’}
random_state : int seed, RandomState instance, or None (default)
n_init : int, optional, default: 10
eigen_tol : float, optional, default: 0.0
assign_labels : {‘kmeans’, ‘discretize’}, default: ‘kmeans’
kernel_params : dictionary of string to any, optional
|
---|
Notes
If you have an affinity matrix, such as a distance matrix, for which 0 means identical elements, and high values means very dissimilar elements, it can be transformed in a similarity matrix that is well suited for the algorithm by applying the Gaussian (RBF, heat) kernel:
np.exp(- X ** 2 / (2. * delta ** 2))
Another alternative is to take a symmetric version of the k nearest neighbors connectivity matrix of the points.
If the pyamg package is installed, it is used: this greatly speeds up computation.
References
Attributes
affinity_matrix_ | (array-like, shape (n_samples, n_samples)) Affinity matrix used for clustering. Available only if after calling fit. |
labels_ | (list of arrays, each of shape [sequence_length, ]) The label of each point is an integer in [0, n_clusters). |
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 |
Methods
__init__([n_clusters, eigen_solver, ...]) | |
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 the clustering on the data
Parameters: | sequences : list of array-like, each of shape [sequence_length, n_features]
|
---|---|
Returns: | self |
Performs clustering on X and returns cluster labels.
Parameters: | sequences : list of array-like, each of shape [sequence_length, n_features]
|
---|---|
Returns: | Y : list of ndarray, each of shape [sequence_length, ]
|
Alias for fit_predict
Get parameters for this estimator.
Parameters: | deep: boolean, optional
|
---|---|
Returns: | params : mapping of string to any
|
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)
|
---|---|
Returns: | Y : array, shape=(n_samples,)
|
Alias for partial_predict
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]
|
---|---|
Returns: | Y : list of arrays, each of shape [sequence_length,]
|
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Returns: | self |
---|
Return some diagnostic summary statistics about this Markov model
Alias for predict