Skip to content

Commit

Permalink
Fatal if set is_unbalance and scale_pos_weight at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
guolinke committed Jul 28, 2017
1 parent eb52262 commit 1c92e75
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/objective/binary_objective.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ namespace LightGBM {
class BinaryLogloss: public ObjectiveFunction {
public:
explicit BinaryLogloss(const ObjectiveConfig& config, std::function<bool(float)> is_pos = nullptr) {
is_unbalance_ = config.is_unbalance;
sigmoid_ = static_cast<double>(config.sigmoid);
if (sigmoid_ <= 0.0) {
Log::Fatal("Sigmoid parameter %f should be greater than zero", sigmoid_);
}
is_unbalance_ = config.is_unbalance;
scale_pos_weight_ = static_cast<double>(config.scale_pos_weight);
if(is_unbalance_ && std::fabs(scale_pos_weight_ - 1.0f) > 1e-6) {

This comment has been minimized.

Copy link
@strint

strint Jul 28, 2017

should this be

if(!is_unbalance_ && std::fabs(scale_pos_weight_ - 1.0f) > 1e-6)

?
which means when the sample is balanced and it's scale_pos_weight is not 1, we report an error.

This comment has been minimized.

Copy link
@guolinke

guolinke Jul 28, 2017

Author Collaborator

I think you mis-understood it. This fatal is to avoid set is_unbalance_ and scale_pos_weight_ at the same time.
Because when set is_unbalance_ =True, the scale_pos_weight_ will be auto calculated.

This comment has been minimized.

Copy link
@strint

strint Jul 28, 2017

You means we use these 2 parameters as below:

  • is_unbalance_=True => auto calculate scale_pos_weight_
  • is_unbalance_= False => user set scale_pos_weight_, can be 1 or other value

?

This comment has been minimized.

Copy link
@guolinke

guolinke Jul 28, 2017

Author Collaborator

yeah.

This comment has been minimized.

Copy link
@strint

strint Jul 28, 2017

ok, got it.

This comment has been minimized.

Copy link
@strint

strint Jul 28, 2017

https://github.com/Microsoft/LightGBM/blob/master/docs/Parameters.md

Comment on is_unbalance may need more explaination, because its relationship with scale_pos_weight is confusing.

Log::Fatal("Cannot set is_unbalance and scale_pos_weight at the same time.");
}
is_pos_ = is_pos;
if (is_pos_ == nullptr) {
is_pos_ = [](float label) {return label > 0; };
Expand Down

0 comments on commit 1c92e75

Please sign in to comment.