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
[TREE] add interaction constraints #3466
Conversation
@BlueTea88 Can you write some tests in R? See |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall. Couple things:
- I'm wondering if there is more efficient way to pass interaction constraints to C++. Instead of 0's and 1's, we can pass the string in the form
[[0, 1, 2], [3, 4]]
and have the DMLC JSON parser parse it tostd::vector<std::vector<int>>
. - A future PR should expose this functionality to Python.
Here is a sample code for accepting #include <dmlc/json.h>
#include <string>
#include <vector>
#include <sstream>
int main(void) {
std::vector<std::vector<int>> int_constraint;
std::istringstream iss("[[1,2],[3,4,5]]");
dmlc::JSONReader reader(&iss);
reader.Read(&int_constraint);
for (const auto& constraint : int_constraint) {
std::cout << "Constraint group: ";
for (int e : constraint) {
std::cout << e << ",";
}
std::cout << std::endl;
}
return 0;
} |
@hcho3 OK, will try to add the things you mentioned |
@hcho3 I added a test in R and made changes based on your comments. For the |
Codecov Report
@@ Coverage Diff @@
## master #3466 +/- ##
===========================================
+ Coverage 45.69% 50.09% +4.4%
Complexity 188 188
===========================================
Files 166 172 +6
Lines 13168 14015 +847
Branches 445 457 +12
===========================================
+ Hits 6017 7021 +1004
+ Misses 6947 6769 -178
- Partials 204 225 +21
Continue to review full report at Codecov.
|
@BlueTea88 I can help you out with C++ part. Let me review your R test and get back to you. |
@BlueTea88 Can you enable "Allow edits by maintainers"? I have a new commit that adds dmlc::JSONReader to the pull request. |
@hcho3 Should be allowed now. Let me know if this still doesn't work. |
@BlueTea88 It still doesn't work. Can you look at it again? |
@hcho3 I have the "allow edits by maintainers" box checked. So i'm not sure why its not working. I've also sent you an invite to be a collaborator in case that can give you more access. |
@BlueTea88 Thanks, I was able to push my commit to your repo. The commit adds dmlc::JSONParser to understand constraints in form of |
OK Thanks. I will make changes to the other parts. |
@khotilov @hcho3 I have updated the R argument so interaction_constraints expects a list of feature IDs instead of column names (so now arguments are no longer dependent on column names being available). Also updated the R example to be more in line with the R coding style. Thanks @hcho3 for the changes to the C++ code. |
@BlueTea88 @khotilov I think this PR is good to merge, once all lint errors are fixed |
…ts; Use sparse arrays for bookkeeping
…ad of column names, fix R coding style
@BlueTea88 @khotilov I added a tutorial for feature interaction constraints. Let me know if the explanation makes sense. Rendered doc: rendered_tutorial.zip |
@hcho3 I think it makes sense. I like the graphs as well. Just the last line: |
@BlueTea88 Yes, let me fix the typo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My last review pass, I promise :)
Nice tutorial @hcho3
Looks good to go! |
* add interaction constraints * enable both interaction and monotonic constraints at the same time * fix lint * add R test, fix lint, update demo * Use dmlc::JSONReader to express interaction constraints as nested lists; Use sparse arrays for bookkeeping * Add Python test for interaction constraints * make R interaction constraints parameter based on feature index instead of column names, fix R coding style * Fix lint * Add BlueTea88 to CONTRIBUTORS.md * Short circuit when no constraint is specified; address review comments * Add tutorial for feature interaction constraints * allow interaction constraints to be passed as string, remove redundant column_names argument * Fix typo * Address review comments * Add comments to Python test
Add interaction constraints as mentioned in #3135 and as previously tried in #3448 before I stuffed up the commits while trying to rebase. At the moment both interaction and monotonic constraints cannot be applied at the same time. But will be able to add in this functionality once #3429 goes through.
Closes #3135