Metrics silhouette persamplefromdistances - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Metrics is 0.4.0 โ€” read its documentation.

Home โ€บ Metrics โ€บ Clustering metrics

Silhouette.PerSampleFromDistances

The score of each sample, from a distance matrix.

public static double[] PerSampleFromDistances(ReadOnlySpan<int> labels, ReadOnlySpan<double> distances)

Parameters โ€” as Silhouette.ScoreFromDistances: labels, and the n ร— n matrix distances row-major.

Returns โ€” double[], one value per sample in the order the samples were given.

Exceptions โ€” ArgumentException when the inputs disagree in size, when a distance is not finite, when a diagonal entry exceeds 100ยทฮต โ€” "The precomputed distance matrix contains non-zero elements on the diagonal. Use np.fill_diagonal(X, 0)." โ€” and when the number of distinct labels falls outside [2, n - 1] โ€” scikit-learn's own bound, carried with its own sentence: Number of labels is 1. Valid values are 2 to n_samples - 1 (inclusive). Last, a negative distance, with pairwise_distances' sentence "Negative values in data passed to pairwise_distances. Precomputed distance need to have non-negative values.." โ€” the double space and the two stops are the reference's, and a matrix holding both a negative entry and a bad label count gets the label sentence, as scikit-learn orders them (#1275).

Example โ€” the same per-sample diagnosis, on a matrix.

using Lodestar.Metrics;

double[] distances =
[
    0.0, 1.0, 9.0,
    1.0, 0.0, 9.0,
    9.0, 9.0, 0.0,
];
int[] labels = [0, 0, 1];

double[] scores = Silhouette.PerSampleFromDistances(labels, distances);
double alone = scores[2];   // => 0

Remarks โ€” the third sample is a cluster of one, so it scores 0, and the other two score high. This is the computation the three other members are written in terms of: Silhouette.Score and Silhouette.PerSample build the euclidean matrix and call it.

Applies to โ€” net10.0, netstandard2.0.

See also โ€” Silhouette.ScoreFromDistances, Silhouette.PerSample, the Python equivalence table.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ