-
Notifications
You must be signed in to change notification settings - Fork 0
✨ Add callable features and better error testing #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f12234
0075af7
5272758
c784e50
194c53e
5e0af90
d0c67ac
52ba39d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,6 @@ jobs: | |
| matrix: | ||
| version: | ||
| - '1.10' | ||
| - '1.6' | ||
| - 'nightly' | ||
| os: | ||
| - ubuntu-latest | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,21 +13,23 @@ logic?" | |
|
|
||
| # Arguments | ||
|
|
||
| - `X`: A table where the elements of the categorical features have [scitypes](https://juliaai.github.io/ScientificTypes.jl/dev/) | ||
| - X: A table where the elements of the categorical features have [scitypes](https://juliaai.github.io/ScientificTypes.jl/dev/) | ||
| `Multiclass` or `OrderedFactor` | ||
| - `features=[]`: A list of names of categorical features given as symbols to exclude or include from encoding | ||
| - `ignore=true`: Whether to exclude or includes the features given in `features` | ||
| - `ordered_factor=false`: Whether to encode `OrderedFactor` or ignore them | ||
| - `feature_mapper`: Defined above. | ||
| - features=[]: A list of names of categorical features given as symbols to exclude or include from encoding, | ||
| according to the value of `ignore`, or a single symbol (which is treated as a vector with one symbol), | ||
| or a callable that returns true for features to be included/excluded | ||
| - ignore=true: Whether to exclude or includes the features given in features | ||
| - ordered_factor=false: Whether to encode OrderedFactor or ignore them | ||
| - feature_mapper: Defined above. | ||
|
|
||
| # Returns | ||
|
|
||
| - `mapping_per_feat_level`: Maps each level for each feature in a subset of the categorical features of | ||
| - mapping_per_feat_level: Maps each level for each feature in a subset of the categorical features of | ||
| X into a scalar or a vector. | ||
| - `encoded_features`: The subset of the categorical features of X that were encoded | ||
| - encoded_features: The subset of the categorical features of X that were encoded | ||
| """ | ||
| function generic_fit(X, | ||
| features::AbstractVector{Symbol} = Symbol[], | ||
| features = Symbol[], | ||
| args...; | ||
| ignore::Bool = true, | ||
| ordered_factor::Bool = false, | ||
|
|
@@ -38,7 +40,22 @@ function generic_fit(X, | |
| feat_names = Tables.schema(X).names | ||
|
|
||
| #2. Modify column_names based on features | ||
| feat_names = (ignore) ? setdiff(feat_names, features) : intersect(feat_names, features) | ||
| if features isa Symbol | ||
| features = [features] | ||
| end | ||
|
|
||
| if features isa AbstractVector{Symbol} | ||
| # Original behavior for vector of symbols | ||
| feat_names = | ||
| (ignore) ? setdiff(feat_names, features) : intersect(feat_names, features) | ||
| else | ||
| # If features is a callable, apply it to each feature name | ||
| if ignore | ||
| feat_names = filter(name -> !features(name), feat_names) | ||
| else | ||
| feat_names = filter(features, feat_names) | ||
| end | ||
| end | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Julia it is unfortunately difficult to recognise callability of an object (at least last time I researched this). So, reverse your logic here: if feature names is a vector of symbols then do X, otherwise do Y. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's an example of a callable that is not a function: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 5e0af90 |
||
| # 3. Define mapping per column per level dictionary | ||
| mapping_per_feat_level = Dict() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.