Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
7b4ead1e
Commit
7b4ead1e
authored
Mar 24, 2017
by
Guolin Ke
Browse files
convert the probabilities to raw score in boost_from_average of classification.
parent
b38a19a4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
4 deletions
+36
-4
include/LightGBM/objective_function.h
include/LightGBM/objective_function.h
+4
-0
src/boosting/gbdt.cpp
src/boosting/gbdt.cpp
+8
-4
src/objective/binary_objective.hpp
src/objective/binary_objective.hpp
+12
-0
src/objective/multiclass_objective.hpp
src/objective/multiclass_objective.hpp
+12
-0
No files found.
include/LightGBM/objective_function.h
View file @
7b4ead1e
...
...
@@ -33,6 +33,10 @@ public:
virtual
const
char
*
GetName
()
const
=
0
;
virtual
std
::
vector
<
double
>
ConvertToRawScore
(
const
std
::
vector
<
double
>&
preds
)
const
{
return
preds
;
}
ObjectiveFunction
()
=
default
;
/*! \brief Disable copy */
ObjectiveFunction
&
operator
=
(
const
ObjectiveFunction
&
)
=
delete
;
...
...
src/boosting/gbdt.cpp
View file @
7b4ead1e
...
...
@@ -306,13 +306,17 @@ bool GBDT::TrainOneIter(const score_t* gradient, const score_t* hessian, bool is
sum_per_class
[
0
]
+=
label
[
i
];
}
}
std
::
vector
<
double
>
init_scores
(
num_class_
);
for
(
int
i
=
0
;
i
<
num_class_
;
++
i
)
{
init_scores
[
i
]
=
sum_per_class
[
i
]
/
num_data_
;
}
init_scores
=
object_function_
->
ConvertToRawScore
(
init_scores
);
for
(
int
curr_class
=
0
;
curr_class
<
num_class_
;
++
curr_class
)
{
double
init_score
=
sum_per_class
[
curr_class
]
/
num_data_
;
std
::
unique_ptr
<
Tree
>
new_tree
(
new
Tree
(
2
));
new_tree
->
Split
(
0
,
0
,
BinType
::
NumericalBin
,
0
,
0
,
0
,
init_score
,
init_score
,
0
,
num_data_
,
1
);
train_score_updater_
->
AddScore
(
init_score
,
curr_class
);
new_tree
->
Split
(
0
,
0
,
BinType
::
NumericalBin
,
0
,
0
,
0
,
init_score
s
[
curr_class
],
init_scores
[
curr_class
]
,
0
,
num_data_
,
1
);
train_score_updater_
->
AddScore
(
init_score
s
[
curr_class
]
,
curr_class
);
for
(
auto
&
score_updater
:
valid_score_updater_
)
{
score_updater
->
AddScore
(
init_score
,
curr_class
);
score_updater
->
AddScore
(
init_score
s
[
curr_class
]
,
curr_class
);
}
models_
.
push_back
(
std
::
move
(
new_tree
));
}
...
...
src/objective/binary_objective.hpp
View file @
7b4ead1e
...
...
@@ -86,6 +86,18 @@ public:
}
}
std
::
vector
<
double
>
ConvertToRawScore
(
const
std
::
vector
<
double
>&
preds
)
const
override
{
std
::
vector
<
double
>
ret
;
for
(
auto
pred
:
preds
)
{
if
(
pred
>
kEpsilon
&&
pred
<
1.0
f
)
{
ret
.
push_back
(
-
std
::
log
(
1.0
f
/
pred
-
1.0
f
)
/
sigmoid_
);
}
else
{
ret
.
push_back
(
0.0
f
);
}
}
return
ret
;
}
const
char
*
GetName
()
const
override
{
return
"binary"
;
}
...
...
src/objective/multiclass_objective.hpp
View file @
7b4ead1e
...
...
@@ -93,6 +93,18 @@ public:
}
}
std
::
vector
<
double
>
ConvertToRawScore
(
const
std
::
vector
<
double
>&
preds
)
const
override
{
std
::
vector
<
double
>
ret
;
for
(
auto
pred
:
preds
)
{
if
(
pred
>
kEpsilon
)
{
ret
.
push_back
(
std
::
log
(
pred
));
}
else
{
ret
.
push_back
(
0
);
}
}
return
ret
;
}
const
char
*
GetName
()
const
override
{
return
"multiclass"
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment