Skip to content

machine_learning: add numeric doctests to gradient_descent - #15286

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:ml/gradient-descent-doctests
Sep 12, 2026
Merged

machine_learning: add numeric doctests to gradient_descent#15286
cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:ml/gradient-descent-doctests

Conversation

@priya-sundaram-dev

@priya-sundaram-dev priya-sundaram-dev commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Continues the per-file doctest effort from #13919 (after #15285 for k_means_clust).

Describe your change:

Adds numeric doctests pinning the deterministic helper functions in machine_learning/gradient_descent.py on the module's fixed train_data/test_data and initial parameter_vector = [2, 4, 1, 5]:

  • output — train/test lookup and the None fallback for an unknown data set
  • _hypothesis_value / calculate_hypothesis_value — hypothesis value incl. bias term, plus the None fallback
  • summation_of_cost_derivative and get_cost_derivative — bias (index=-1) and feature (index=0) cases

All values are computed from the file's own fixed data, so the tests are fully deterministic and don't touch the global-mutating run_gradient_descent. python -m doctest passes (12/12); ruff check and ruff format clean.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

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.
  • 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 issue, please mention Closes #{}.

@cclauss
cclauss merged commit 611418c into TheAlgorithms:master Sep 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants