Skip to content

Commit

Permalink
Remove check for feature in feature_importance
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Dec 4, 2023
1 parent b38fd0c commit 4b774fb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 10 deletions.
5 changes: 0 additions & 5 deletions src/importance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,14 @@ function feature_importance(
feat_name::String
)
importance = 0.0
found_feature = false
for (i, rule) in enumerate(model.rules)
for subclause::SubClause in subclauses(rule)
if feature_name(subclause)::String == feat_name
found_feature = true
weight = model.weights[i]
importance += _rule_importance(weight, rule)
end
end
end
if !found_feature
throw(ArgumentError("Feature `$feat_name` not found in the model."))
end
return importance
end

Expand Down
5 changes: 0 additions & 5 deletions test/importance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ end
# and 2 classes: [0, 1].
# Note: showing only the probability for class 1 since class 0 has probability 1 - p.

let
msg = "Feature `x1` not found in the model."
@test_throws ArgumentError(msg) feature_importance(model, "x1")
end

importance = feature_importance(model, "1")
# Based on the numbers above.
expected = w1 * (0.4 - 0.1) + w2 * (0.3 - 0.2)
Expand Down

4 comments on commit 4b774fb

@rikhuijzer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96427

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.1 -m "<description of version>" 4b774fbf4b41cb8618285a9d4daea233c209a432
git push origin v2.0.1

@rikhuijzer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Made the feature_importance function more flexible by allowing the function to be called on feature names that are not in the model under consideration.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/96427

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.1 -m "<description of version>" 4b774fbf4b41cb8618285a9d4daea233c209a432
git push origin v2.0.1

Please sign in to comment.