scikit-learn / scikit-learn/scikit-learn

Support sample weight in clusterers

Open
#3,998 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement help wanted Moderate module:cluster
Dominant language
Python
Stars
67.3k
Forks
27.4k
Avg merge
1d 15h
Merged PRs (30d)
58

Description

Currently no clusterers (or clustering metrics) support weighted dataset (although support for DBSCAN is proposed in #3994).

Weighting can be a compact way of representing repeated samples, and may affect cluster means and
variance, average link between clusters, etc.

Ideally BIRCH's global clustering stage should be provided a weighted dataset, and is current use of unweighted representatives may make its parametrisation more brittle.

This could be subject to an invariance test along the lines of:

sample_weight = np.random.randint(0, 10, size=X.shape[0])
weighted_y = clusterer.fit_predict(X, sample_weight=sample_weight)
repeated_y = clusterer.fit_predict(np.repeat(X, sample_weight))
assert_equal(adjusted_rand_score(np.repeat(weighted_y, sample_weight), repeated_y)
# NB: this is only a useful sufficient test if weighted_y differs from clusterer.fit_predict(X)

(There is also a minor question of whether sample_weight should be universally accepted by ClusterMixin or whether WeightedClusterMixin should be created, etc.)

Sample weight support for clusterers:

  • Affinity propagation (I don't know this well enough to know the applicability)
  • BIRCH
  • DBSCAN
  • Hierarchical -> Ward link
  • Hierarchical -> Complete link (N/A, as far as I can tell)
  • Hierarchical -> Average link
  • K Means
  • Minibatch K Means
  • Mean shift
  • Spectral

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the clusterer implementations named in the checklist, especially BIRCH, hierarchical average linkage, mean shift, and spectral clustering, and review the proposed invariance test using sample_weight and np.repeat. Done means the applicable unchecked clusterers and relevant metrics accept weighted data with tests showing equivalent results for weighted versus repeated samples.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
machine-learning, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.