Skip to content

Implementation of Density-based spatial clustering of applications with noise (DBSCAN) ML Algorithm - #11671

Open
tkgowtham wants to merge 31 commits into
TheAlgorithms:masterfrom
tkgowtham:master
Open

Implementation of Density-based spatial clustering of applications with noise (DBSCAN) ML Algorithm#11671
tkgowtham wants to merge 31 commits into
TheAlgorithms:masterfrom
tkgowtham:master

Conversation

@tkgowtham

@tkgowtham tkgowtham commented Oct 2, 2024

Copy link
Copy Markdown

Describe your change:

Implementation of Density-based spatial clustering of applications with noise (DBSCAN) Algorithm using Python from Scratch

How it works :
Take every point and see how many other points are close to it by e (epsilon) radius distance. If that point has covered minimum of number of points (minPts), then it will be considered as Core else Noise. An Noise can also be classified as Border if it falls into the area covered by the core point.

Reference Website : https://en.wikipedia.org/wiki/DBSCAN
Reference YouTube Video : https://youtu.be/-p354tQsKrs?si=TkI9nrnAiqDHyjR-

  • Add an algorithm?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Oct 2, 2024
@algorithms-keeper algorithms-keeper Bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Oct 2, 2024
@algorithms-keeper algorithms-keeper Bot removed the tests are failing Do not merge until tests pass label Oct 2, 2024
@tkgowtham

Copy link
Copy Markdown
Author

Hi, can someone please kindly review my code. All the test cases passed. If any changes/improvements needed please feel free to tell !!!

@tkgowtham

tkgowtham commented Oct 4, 2024

Copy link
Copy Markdown
Author

@cclauss @tianyizheng02 Can you please review this PR and let me know if any changes in needed. Thanks in advance.

@tkgowtham tkgowtham changed the title Implementation of DBSCAN Algorithm Implementation of Density-based spatial clustering of applications with noise (DBSCAN) ML Algorithm Oct 5, 2024
@cclauss

cclauss commented Sep 10, 2026

Copy link
Copy Markdown
Member

@priya-sundaram-dev, your review, please.

@priya-sundaram-dev priya-sundaram-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @tkgowtham 🙂 I pulled the branch and ran the doctests locally with the Agg backend — all 12 pass, and the DBSCAN core/border/noise classification looks correct (each point counts itself in its ε-neighborhood, so the >= minpts core test is right).

A few suggestions, mostly small — none are hard blockers, but the type-hint one is worth fixing since the repo type-checks:

  1. radius type hint. It's annotated radius: int, but every example passes a float (1.9, 2.5). Please change it to radius: float.

  2. Sentinel default for file. Using the string "None" as a sentinel (file: str = "None" + if file != "None") is fragile — a real file literally named None would break it, and the attribute can actually hold either a str path or a tuple[dict, ...]. Prefer:

    file: str | None = None
    ...
    self.file = file if file is not None else (...)
  3. isinstance over type() is. if type(self.file) is str: reads better as if isinstance(self.file, str): (and satisfies linters).

  4. Naming. e and dict1 are hard to follow — eps/radius and neighbors would make perform_dbscan much clearer for readers learning the algorithm.

  5. Minor / optional: standard DBSCAN uses dist <= eps (inclusive) rather than dist < eps. Your doctests are internally consistent either way, so this is just a note. Also perform_dbscan is O(n²) pairwise, which is totally fine for a teaching implementation — maybe add a one-line comment saying so.

Nice, well-documented submission overall. Fix the radius: float hint and the isinstance line and I think it's in good shape. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants