Add comprehensive variable pre-filtering mechanism with categorical support to br_run and br_pipeline functions#51
Merged
Merged
Conversation
…ipeline Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] 增加一个选项实现br_run的变量
Add variable pre-filtering mechanism to br_run and br_pipeline functions
Aug 9, 2025
x的预过滤机制
Contributor
|
categorical variables 也支持过滤,比如如果一个x如果只有一种分类,这种列肯定要过滤掉对吧? 目前数据科学领域对一般分类变量过滤会采用什么策略呢?怎么实现呢? 请校对和测试所有的计算逻辑,并确保所有test通过 |
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Contributor
Author
You're absolutely right! I've enhanced the filtering mechanism to support categorical variables. The implementation now: Categorical Variable Filtering:
Common Data Science Strategies Implemented:
Example Results: # Before: categorical variables with single levels were kept
# After: they are properly filtered out
Pre-filtering removed 5 out of 9 focal variables (55.6%)
Filtered variables: "constant_numeric", "constant_character", "constant_factor", "constant_logical", and "high_na_var"Usage: # Default behavior (filters single-level categoricals)
br_pipeline(data, y = "outcome", x = variables, method = "gaussian", filter_x = TRUE)
# Custom threshold for categorical levels
br_run(obj, filter_x = TRUE, filter_min_levels = 3) # Requires at least 3 levelsAll computational logic has been verified with comprehensive tests covering numeric, character, factor, and logical variables. All existing tests continue to pass, ensuring backward compatibility. Commit: 889f532 |
Copilot
AI
changed the title
Add variable pre-filtering mechanism to br_run and br_pipeline functions
Add comprehensive variable pre-filtering mechanism with categorical support to br_run and br_pipeline functions
Aug 9, 2025
Enhanced the variable filtering logic in filter_variables_x to better handle categorical variables and minimum level requirements. Updated br_run to enforce that br_set_x and br_set_y are called before execution. Improved documentation and examples for pipeline functions, and expanded unit tests to cover categorical filtering and edge cases. Minor code formatting and consistency improvements throughout.
ShixiangWang
marked this pull request as ready for review
August 9, 2025 16:24
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.
This PR implements a comprehensive pre-filtering mechanism for focal variables (
x) in bothbr_run()andbr_pipeline()functions to address issues with variables that lack analytical significance, including both numeric and categorical variables.Problem
Focal variables in regression analysis may include terms with:
These problematic variables can cause modeling failures or produce unreliable results, requiring manual data cleaning before analysis.
Solution
Added optional pre-filtering capabilities with the following new parameters:
filter_x: Enable/disable filtering (default:FALSEfor backward compatibility)filter_na_prop: Maximum proportion of NA values allowed (default:0.8)filter_sd_min: Minimum standard deviation required for numeric variables (default:1e-6)filter_var_min: Minimum variance required for numeric variables (default:1e-6)filter_min_levels: Minimum unique levels required for categorical variables (default:2)Key Features
Smart Filtering Logic:
I(x^2), interactions)Categorical Variable Filtering:
filter_min_levelsUser Experience:
Usage Examples:
Example Output:
Implementation Details
filter_variables_x()helper function in98-utils.Rbr_run()andbr_pipeline()function signaturesTesting
The implementation includes extensive tests covering:
br_run()andbr_pipeline()workflowsfilter_min_levels)filter_x = FALSE)Fixes #50.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.