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.
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
[R-package] Add sparse feature contribution predictions #5108
[R-package] Add sparse feature contribution predictions #5108
Changes from 21 commits
508fb1b
557a005
a740dc8
631c935
82900f6
6fd0868
398ddb9
7d53353
19b706f
8b016b8
df49aaa
5df97de
6eeddc4
e04c6f4
4ac5a3b
e38a6d7
5b65fd1
c00a8ff
d905910
edaac4e
ab86ad3
005707d
3f8467a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Can you please test this behavior, by adding these new combinations of
predcontrib = TRUE
+ new{Matrix}
classes to the tests from #4977?LightGBM/R-package/tests/testthat/test_Predictor.R
Line 155 in 3798f87
LightGBM/R-package/tests/testthat/test_Predictor.R
Line 166 in 3798f87
Every PR adding new behavior to the package should include tests on that behavior, to catch unexpected issues with the implementation and to prevent future development from accidentally breaking that behavior.
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.
Those are already tested in the tests from the PR for row names.
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.
They are not. The links in my comment point to tests on
"CsparseMatrix"
objects, but if you click them you won't see tests on the types referenced in this PR:"dsparseMatrix"
,"dsparseVector"
,"dgRMatrix"
,"dgCMatrix"
.Is there something I've misunderstood about the relationship between these classes?
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.
There's a class hierarchy...
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.
Please tell us specifically what you mean by "there's a class hierarchy", and why it means that you don't want to add the tests I'm asking you to add.
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.
dgCMatrix
is a subclass ofCsparseMatrix
, which is a subclass ofsparseMatrix
, and so on. Classes likedsparseMatrix
are abstract.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.
Thanks for that. I'm still struggling to understand how that means that the tests I'm asking for shouldn't be added.
Consider the case added in this PR beginning with
} else if (inherits(data, "dgRMatrix")) {
. It doesn't contain areturn()
statement, so that at the end of theif - else if
block, the "possibly add row names" code (the line this comment thread is on) will run.If someone were to add
return(out)
on line 193, that "possibly add row names" code wouldn't be reached. I think it's desirable for a test to fail in that case, to inform us that adding thatreturn
statement is a breaking change that causes row names to not be set on the predictions.The tests I linked test a regular dense R matrix and a
CsparseMatrix
. As the example below shows, that means they don't currently cover the cases where the input topredict()
is a"dgRMatrix"
or a"dsparseVector"
.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.
Ok, if you really want to have tests for everything, I've added a test for CSR matrices. A vector representing a single row cannot have row names so I left that out of tests.
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.
Thank you, yes I do. The more of this project's behaviors are reflected in tests, the less likely it is that future changes silently break that behavior. This project is too large for all of these concerns to just be kept in maintainers' heads and enforced through PR comments.
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.
Beyond just testing the type of the returned objects, can you also please add assertions that the predicted values are the same for all of these cases, and that they're the same as those predicted for a regular R matrix?
Those
.Call()
calls involve passing a lot of positional arguments with similar values, so such assertions would give us greater confidence that this is working correctly.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.
I thought missing data was handled the same way as xgboost, which means predictions for sparse outputs should be different from those of dense inputs.
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.
I believe the sparse and dense data structures here are just different representations in memory of the exact same matrices, and that specialized methods for them in LightGBM are just intended to allow that sparse data to stay sparse throughout training + scoring.
And I believe that's not directly related to the handling of missing data (which is described in more detail in the discussion at #2921 (comment) and at https://lightgbm.readthedocs.io/en/latest/Advanced-Topics.html?highlight=missing#missing-value-handle).
Consider the following example:
If you find a case where this is not true and LightGBM is creating different predictions for sparse and, I'd consider that a bug worth addressing.
@shiyu1994 @guolinke @StrikerRUS please correct me if I've misspoken.
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.
Good to know, would be useful to have that in the docs, since xgboost works differently (treats non-present sparse entries as missing instead of as zeros) and one might assume both libraries would work the same way.
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.
Oh interesting, I did not know that. https://xgboost.readthedocs.io/en/stable/faq.html#why-do-i-see-different-results-with-sparse-and-dense-data
LightGBM's documentation does already describe this behavior directly. Please see https://lightgbm.readthedocs.io/en/latest/Advanced-Topics.html#missing-value-handle