-
Notifications
You must be signed in to change notification settings - Fork 2k
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
PUBDEV-7909 fix how gain is calculated in xgbfi for gbm #5141
PUBDEV-7909 fix how gain is calculated in xgbfi for gbm #5141
Conversation
15681bd
to
9aa549d
Compare
9aa549d
to
e374ab8
Compare
} | ||
|
||
@Test | ||
public void testXGBoostFeatureInteractionsCheckRanksVsVarimp() { |
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.
XGBoost?
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.
} | ||
} | ||
|
||
DKV.remove(f._key); |
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.
Why?
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.
not needed since already tracked by scope, will remove
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.
|
||
SharedTreeSubgraph treeSubgraph = model.getSharedTreeSubgraph(0, 0); | ||
|
||
String[] keysToCheck = new String[]{"DPROS", "ID", "PSA", "GLEASON", "VOL"}; |
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.
Should ID column be in ignored_columns?
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.
@@ -609,4 +610,17 @@ public final int getRightChildIndex() { | |||
return rightChild != null ? rightChild.internalId : -1; | |||
} | |||
|
|||
public float getGain() { | |||
if (!Float.isNaN(gain)) { |
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.
is this because the same code handles XGB and GBM?
if so it would be better to have a flag, eg.: useSEforGain and switch on that
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.
yes, useSEforGain will be better
} | ||
|
||
@Test | ||
public void testXGBoostFeatureInteractionsCheckRanksVsVarimp() { |
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.
confusing test name
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.
|
||
DKV.remove(f._key); | ||
} finally { | ||
if( model != null ) model.delete(); |
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.
why not use scope?
@@ -609,4 +610,15 @@ public final int getRightChildIndex() { | |||
return rightChild != null ? rightChild.internalId : -1; | |||
} | |||
|
|||
public float getGain(boolean useSEforGain) { | |||
if (useSEforGain) { |
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.
where is useSEforGain
defined? I dont think useSquaredErrorForGain
is too long, but much more readable
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.
it depends on whether you call GBMModel.getFeatureInteractions(...) or XGBoostModel.getFeatureInteractions(). for XGB, gain is prepared in boosterbyte and set in XGBoostModel.constructSubgraph(...) so useSquaredErrorForGain = false, for GBM it's not prepared and it has to be calculated from squared error, so useSquaredErrorForGain = true
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.
sorry, stupid question, I missed the method arg boolean useSEforGain
knit: would also use the long name here
839f6e3
to
a95a715
Compare
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, minor improvement suggestions
try { | ||
Frame f = Scope.track(parse_test_file("smalldata/logreg/prostate.csv")); | ||
f.replace(f.find("CAPSULE"), f.vec("CAPSULE").toNumericVec()); | ||
DKV.put(f); |
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.
unnecessary I think
@@ -609,4 +610,15 @@ public final int getRightChildIndex() { | |||
return rightChild != null ? rightChild.internalId : -1; | |||
} | |||
|
|||
public float getGain(boolean useSEforGain) { | |||
if (useSEforGain) { |
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.
sorry, stupid question, I missed the method arg boolean useSEforGain
knit: would also use the long name here
for (Map.Entry<String, FeatureInteraction> featureInteraction : featureInteractions1.entrySet()) { | ||
list1.add(new KeyValue(featureInteraction.getKey(), featureInteraction.getValue().gain)); | ||
} | ||
list1.sort((a,b) -> a.getValue() < b.getValue() ? -1 : a.getValue() == b.getValue() ? 0 : 1); |
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.
could be simplified with Comparator.comparing(KeyValue::getValue)
} | ||
list2.sort((a,b) -> a.getValue() < b.getValue() ? -1 : a.getValue() == b.getValue() ? 0 : 1); | ||
|
||
List<String> sortedKeys1 = list1.stream().map(KeyValue::getKey).collect(Collectors.toList()); |
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.
sorting could be merged into the stream().sorted(Comparator.comparing().map()...
442a5e1
to
d9f409f
Compare
No description provided.