Skip to content

Pruthviraj Gojare — R23-T045: How CI tests machine_learning/random_forest_classifier.py #46

Open

Description

@ankushbisht01

Student: Pruthviraj Gojare

Task: R23-T045 · 5 of 10
Repository: https://github.com/S-AI-Projects/TheAlgorithms-Python
Assigned working branch: student/e26b07f0834

Goal

Explore how the repository's CI collects, runs and reports on this file. This file has no doctests and only a main() using scikit-learn. What does CI actually test here? Make it testable: a function returning accuracy with a fixed random_state, plus a doctest.

Steps

  1. Read .github/workflows/build.yml (the pytest command, the --ignore list, coverage) and pyproject.toml [tool.pytest].
  2. Run the CI-equivalent command for just this file with -v and coverage: uv run pytest machine_learning/random_forest_classifier.py --cov=machine_learning --cov-report=term-missing -v.
  3. Find this file in DIRECTORY.md and explain how scripts/build_directory_md.py and scripts/validate_filenames.py treat it.
  4. Write work/R23-T045/CI_NOTES.md answering the question in the goal with evidence.
  5. Make the code change in the repository: machine_learning/random_forest_classifier.py: a function returning accuracy with a fixed random_state, type hints and a doctest, keeping main() as a demo. Re-run the automated check and the repo's own tests afterwards.
  6. Prepare the PR: on branch R23-T045, commit the code change plus your work/R23-T045/ evidence, put your findings in the PR description and open the PR against the org fork. For a later upstream PR, create a second branch containing only the code change (no work/ folder).

Done when

☐ CI_NOTES.md explains that pytest currently collects nothing testable from this file (0 doctests, only main()).
☐ machine_learning/random_forest_classifier.py gains a typed function returning accuracy with random_state fixed, plus a doctest asserting accuracy above a stated threshold; main() still runs.
☐ uv run pytest machine_learning/random_forest_classifier.py -v now shows the new doctest passing.

Additional task guidance

Additional curated task guidance

Item:
machine_learning/random_forest_classifier.py (43 lines; 0 doctests)

Task type:
CI & repo tooling

Code change (goes into the PR):
machine_learning/random_forest_classifier.py: a function returning accuracy with a fixed random_state, type hints and a doctest, keeping main() as a demo.

Automated check:
uv run pytest machine_learning/random_forest_classifier.py --cov=machine_learning --cov-report=term-missing -v

Prerequisites:
Linux/WSL2/Codespaces with uv (https://docs.astral.sh/uv/getting-started/installation/); run uv sync --group=test once – it installs the Python version CI uses (.python-version = 3.15t) and the test dependencies, about 1–2 GB

Upstream PR rules:
Follow CONTRIBUTING.md: type hints on every parameter/return, doctests for valid and erroneous input, snake_case file names, no duplicate of an existing implementation, no hand edits to DIRECTORY.md. CI (pytest with doctests, ruff) must pass – bots close PRs without tests or type hints. Keep work/ (benchmarks, notes, property tests) out of the upstream branch; put results in the PR description.

Source (pinned):
https://github.com/TheAlgorithms/Python/blob/574d100b7181956e9c8384552fd078165e4cc326/machine_learning/random_forest_classifier.py

Change:
No change recorded

PR destination:
Preserved pilot guidance

Submission checklist

  • Complete this task and its checks.
  • Add the required evidence and link your pull request here.
  • Select this S-AI-Projects fork as the PR base repository.
  • Request instructor review.

Keep this PR focused on this task. Do not submit assignment PRs to the upstream repository.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions