scikit-learn / scikit-learn/scikit-learn

Implementing partial_fit for NearestCentroid

Open
#12,952 32 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

The NearestCentroid classifier (https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.NearestCentroid.html) does not currently have a partial_fit method, but it would be very useful when running the algorithm in an online fashion. The math for implementing it is simple; it's just a matter of updating the centroids weighted by the number of samples. The implementation could be similar to the partial_fit method of the GaussianNB classifier (except for the obvious mathematical differences). I'm happy to submit an implementation of this, but I wanted to gather input first to see if others have already done this and whether others would find this useful.

Steps/Code to Reproduce

Look at NearestCentroid classifier code and notice that it has not partial_fit method.

Expected Results

There should be a partial_fit method.

Actual Results

There is no partial_fit method.

Versions

N/A

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

Review the NearestCentroid classifier code and compare it with GaussianNB's partial_fit implementation. Determine the required online centroid updates and API behavior, then verify that partial_fit supports the expected incremental workflow with appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.