clustering-tfjs
Version:
High-performance TypeScript clustering algorithms (K-Means, Spectral, Agglomerative) with TensorFlow.js acceleration and scikit-learn compatibility
30 lines • 1.42 kB
TypeScript
import { DataMatrix, LabelVector } from '../clustering/types';
/**
* Computes the Silhouette score.
*
* The silhouette coefficient for a sample is (b - a) / max(a, b) where:
* - a is the mean distance between a sample and all other points in the same cluster
* - b is the mean distance between a sample and all points in the nearest cluster
*
* The score ranges from -1 to +1:
* - +1: Sample is far from neighboring clusters (well clustered)
* - 0: Sample is on or very close to the decision boundary
* - -1: Sample might have been assigned to the wrong cluster
*
* @param X - Data matrix of shape [n_samples, n_features]
* @param labels - Cluster labels for each sample
* @returns The mean silhouette score across all samples
* @throws Error if k <= 1
*/
export declare function silhouetteScore(X: DataMatrix, labels: LabelVector): number;
/**
* Computes the Silhouette score for specific samples (subset).
* Useful for large datasets where computing all pairwise distances is prohibitive.
*
* @param X - Data matrix of shape [n_samples, n_features]
* @param labels - Cluster labels for each sample
* @param sampleIndices - Indices of samples to compute silhouette for
* @returns The mean silhouette score for the specified samples
*/
export declare function silhouetteScoreSubset(X: DataMatrix, labels: LabelVector, sampleIndices: number[]): number;
//# sourceMappingURL=silhouette.d.ts.map