Skip to content

Added Random Forest Regressor as an additional prediction model. - #12767

Merged
cclauss merged 21 commits into
TheAlgorithms:masterfrom
priyanshu-8789:master
Sep 23, 2026
Merged

cclauss merged 21 commits into
TheAlgorithms:masterfrom
priyanshu-8789:master

Conversation

@priyanshu-8789

@priyanshu-8789 priyanshu-8789 commented May 24, 2025

Copy link
Copy Markdown
Contributor

Describe your change:

Implemented RandomForestRegressor alongside SVR and SARIMAX

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • 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.
  • 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 the tests are failing Do not merge until tests pass label May 24, 2025
@priyanshu-8789

Copy link
Copy Markdown
Contributor Author

Implemented RandomForestRegressor alongside SVR and SARIMAX
It will help to improve robustness and accuracy in data safety checking
Updated the voting mechanism to include Random Forest predictions

@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label May 24, 2025
@priyanshu-8789

Copy link
Copy Markdown
Contributor Author

Added Random Forest Regressor to main voting

@algorithms-keeper algorithms-keeper Bot removed the tests are failing Do not merge until tests pass label May 24, 2025
@priyanshu-8789

priyanshu-8789 commented May 24, 2025

Copy link
Copy Markdown
Contributor Author

Hi @poyea,
I've added the Random Forest Regressor as an additional prediction model. All checks have passed.
Could you please review and approve this pull request when convenient?
Thank you!

@priyanshu-8789

Copy link
Copy Markdown
Contributor Author

Hi @TheAlgorithms,
I've added the Random Forest Regressor as an additional prediction model. All checks have passed.
Could you please review and approve this pull request when convenient?
Thank you!

priyanshu-8789 and others added 3 commits May 25, 2025 19:47
Used matplotlib to plot actual vs predicted user count, forecast confidence intervals, outlier thresholds from IQR.
Added logging instead of print because in production, print() is not scalable.
@algorithms-keeper algorithms-keeper Bot added the tests are failing Do not merge until tests pass label May 25, 2025
@algorithms-keeper algorithms-keeper Bot removed the tests are failing Do not merge until tests pass label May 25, 2025
@priyanshu-8789

Copy link
Copy Markdown
Contributor Author

Hi @TheAlgorithms,
I've added the Random Forest Regressor as an additional prediction model and added matplotlib library for seeing predictions vs actuals which will help non-technical users validate data easily. All checks have passed.
Could you please review and approve this pull request when convenient?
Thank you!

@poyea
poyea requested review from Copilot and poyea May 18, 2026 22:04
@poyea poyea self-assigned this May 18, 2026

Copilot AI 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.

Pull request overview

This PR extends the existing forecasting “voting” script by adding a Random Forest–based regressor as an additional prediction option, and introduces a small visualization helper for comparing predictions. It also updates the repository’s directory index.

Changes:

  • Add random_forest_regressor() (sklearn) and include it in the res_vote ensemble.
  • Add plot_forecast() (matplotlib) and call it from the __main__ block to visualize results.
  • Update DIRECTORY.md to add a Geometry index entry.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
machine_learning/forecasting/run.py Adds RandomForestRegressor forecasting method and a matplotlib plotting helper; integrates both into the main execution path.
DIRECTORY.md Adds a Geometry section index entry (“Segment Intersection”).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread machine_learning/forecasting/run.py
Comment thread machine_learning/forecasting/run.py Outdated
Comment thread DIRECTORY.md
@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels Sep 4, 2026
@algorithms-keeper algorithms-keeper Bot added the merge conflicts Open a new PR or rebase on the latest commit label Sep 4, 2026
@algorithms-keeper algorithms-keeper Bot removed the merge conflicts Open a new PR or rebase on the latest commit label Sep 22, 2026
@cclauss

cclauss commented Sep 23, 2026

Copy link
Copy Markdown
Member

@priya-sundaram-dev We already have the file machine_learning/random_forest_regressor.py

Does it add anything to have another implementation?

@cclauss

cclauss commented Sep 23, 2026

Copy link
Copy Markdown
Member

@algorithms-keeper review-all

@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Sep 23, 2026
@algorithms-keeper

Copy link
Copy Markdown
Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.


machine_learning/forecasting/run.py:148: As there is no test file in this pull request nor any test function or class in the file machine_learning/forecasting/run.py, please provide doctest for the function plot_forecast

machine_learning/forecasting/run.py:148: Please provide return type hint for the function: plot_forecast. If the function does not return a value, please provide the type hint as: def function() -> None:

machine_learning/forecasting/run.py:148: Please provide type hint for the parameter: actual

machine_learning/forecasting/run.py:148: Please provide type hint for the parameter: predictions


Content format: [file path]:[line number]: [message]

@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Thanks @cclauss. Distinguishing the two: machine_learning/random_forest_regressor.py is a standalone RF-on-a-real-dataset teaching file, whereas this PR adds random_forest_regressor() as a 4th forecasting voter alongside LinReg / SARIMAX / SVR inside forecasting/run.py's data-safety demo. So it's not a strict duplicate — an extra ensemble member in that voting demo is defensible.

The regressor function itself is clean and its doctest is deterministic — I ran it locally and random_forest_regressor([[5,2],[1,5],[6,2]], [[3,2]], [2,1,4]) does return 1.95 (fixed random_state=42), so CI should be green there. ✅

Two things I'd ask for before merge, though:

  1. plot_forecast() is dead code and violates repo standards. It has no type hints and no doctest (both required by CONTRIBUTING.md), and nothing ever calls it — the __main__ block builds res but never plots. It's the sole reason matplotlib is imported. I'd drop plot_forecast() and the matplotlib import entirely; that also keeps the PR to a single logical change (the checklist claims "only changes one algorithm file", but the plotting is unrelated scope).

  2. With that removed, this becomes a tidy ~15-line addition of one tested regressor. If @author wants plotting, that's a separate PR.

So: not a duplicate, but please strip the unused plotting + matplotlib import, then I think it's a reasonable incremental add. Happy to re-review.

@cclauss

cclauss commented Sep 23, 2026

Copy link
Copy Markdown
Member

@priya-sundaram-dev Can you please add one or more GitHub suggestions that enable us to drop plot_forecast and its imports?

@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 adding the RF regressor — the random_forest_regressor doctest is deterministic (random_state=421.95) and it's a genuine 4th voter, so that part is good to merge. The only blocker is the plotting: plot_forecast is unused dead code, has no type hints/doctest, and is the sole reason matplotlib gets imported (an extra heavy dependency pulled in at import time for a function that only runs an interactive plt.show()). Here are three suggestions to drop it cleanly — accepting all three keeps the RF addition and removes only the plotting:

Comment thread machine_learning/forecasting/run.py Outdated
Comment thread machine_learning/forecasting/run.py Outdated
Comment thread machine_learning/forecasting/run.py Outdated
Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>
@algorithms-keeper algorithms-keeper Bot removed require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Sep 23, 2026
@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 23, 2026
@cclauss
cclauss requested a review from poyea September 23, 2026 19:42
@cclauss
cclauss dismissed poyea’s stale review September 23, 2026 19:45

That function was deleted.

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

Labels

enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants