Refactor predict() to use grouped iteration instead of O(n²) dataframe filtering#75
Open
midaa1 wants to merge 11 commits intoruxailab:mainfrom
Open
Refactor predict() to use grouped iteration instead of O(n²) dataframe filtering#75midaa1 wants to merge 11 commits intoruxailab:mainfrom
midaa1 wants to merge 11 commits intoruxailab:mainfrom
Conversation
Removed push trigger for main branch and unused steps.
Added push event trigger for CI workflow and included steps for Heroku CLI installation and deployment.
Removed push trigger and Heroku deployment steps from CI workflow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes the data aggregation step inside predict() in this issue #74 by removing row-wise dataframe iteration and repeated filtering.
Changes Made
Replaced:
df_data.iterrows() loop
Per-row dataframe filtering based on (True X, True Y)
Added:
Single-pass iteration over:
df_data.groupby("True XY")
Direct extraction of grouped predictions using:
Reused existing precomputed metrics:
Before
Nested logic caused repeated full-dataframe scans.
Complexity: O(n²).
Duplicate processing for identical truth coordinates.
After
Each (True X, True Y) group processed once.
Complexity reduced to O(n).
Cleaner and more readable logic.
Performance Impact
Significant speed improvements on larger datasets.
Reduced CPU usage and memory overhead.
Behavior Verification
Output dictionary structure remains unchanged.
Precision and accuracy values unchanged.
Filtering of negative predictions still respected.
Notes
This refactor prepares the code for better scalability and aligns the aggregation logic with pandas best practices.