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
e0ec8661
"include/git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "b752170ba950890dd7e211fdecedef4d8deffb8b"
Commit
e0ec8661
authored
Apr 22, 2017
by
Guolin Ke
Browse files
refactor the counting for classes.
parent
ea37b10b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
11 deletions
+15
-11
src/boosting/gbdt.cpp
src/boosting/gbdt.cpp
+15
-11
No files found.
src/boosting/gbdt.cpp
View file @
e0ec8661
...
@@ -166,16 +166,14 @@ void GBDT::ResetTrainingData(const BoostingConfig* config, const Dataset* train_
...
@@ -166,16 +166,14 @@ void GBDT::ResetTrainingData(const BoostingConfig* config, const Dataset* train_
if
(
objective_function_
!=
nullptr
&&
objective_function_
->
SkipEmptyClass
())
{
if
(
objective_function_
!=
nullptr
&&
objective_function_
->
SkipEmptyClass
())
{
CHECK
(
num_tree_per_iteration_
==
num_class_
);
CHECK
(
num_tree_per_iteration_
==
num_class_
);
// + 1 here for the binary classification
// + 1 here for the binary classification
class_default_output_
=
std
::
vector
<
double
>
(
num_tree_per_iteration_
+
1
,
0.0
f
);
class_default_output_
=
std
::
vector
<
double
>
(
num_tree_per_iteration_
,
0.0
f
);
std
::
vector
<
data_size_t
>
cnt_per_class
(
num_tree_per_iteration_
+
1
,
0
);
auto
label
=
train_data_
->
metadata
().
label
();
auto
label
=
train_data_
->
metadata
().
label
();
for
(
int
i
=
0
;
i
<
num_data_
;
++
i
)
{
int
index
=
static_cast
<
int
>
(
label
[
i
]);
//Check if user gave a multi-class dataset for a binary class problem.
if
(
index
<=
num_tree_per_iteration_
)
++
cnt_per_class
[
static_cast
<
int
>
(
label
[
i
])];
}
if
(
num_tree_per_iteration_
>
1
)
{
if
(
num_tree_per_iteration_
>
1
)
{
// multi-class
std
::
vector
<
data_size_t
>
cnt_per_class
(
num_tree_per_iteration_
,
0
);
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
++
cnt_per_class
[
static_cast
<
int
>
(
label
[
i
])];
}
for
(
int
i
=
0
;
i
<
num_tree_per_iteration_
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num_tree_per_iteration_
;
++
i
)
{
if
(
cnt_per_class
[
i
]
==
num_data_
)
{
if
(
cnt_per_class
[
i
]
==
num_data_
)
{
class_need_train_
[
i
]
=
false
;
class_need_train_
[
i
]
=
false
;
...
@@ -186,11 +184,17 @@ void GBDT::ResetTrainingData(const BoostingConfig* config, const Dataset* train_
...
@@ -186,11 +184,17 @@ void GBDT::ResetTrainingData(const BoostingConfig* config, const Dataset* train_
}
}
}
}
}
else
{
}
else
{
// binary classification.
// binary class
if
(
cnt_per_class
[
1
]
==
0
)
{
data_size_t
cnt_pos
=
0
;
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
if
(
label
[
i
]
>
0
)
{
++
cnt_pos
;
}
}
if
(
cnt_pos
==
0
)
{
class_need_train_
[
0
]
=
false
;
class_need_train_
[
0
]
=
false
;
class_default_output_
[
0
]
=
-
std
::
log
(
1.0
f
/
kEpsilon
-
1.0
f
);
class_default_output_
[
0
]
=
-
std
::
log
(
1.0
f
/
kEpsilon
-
1.0
f
);
}
else
if
(
cnt_p
er_class
[
1
]
==
num_data_
)
{
}
else
if
(
cnt_p
os
==
num_data_
)
{
class_need_train_
[
0
]
=
false
;
class_need_train_
[
0
]
=
false
;
class_default_output_
[
0
]
=
-
std
::
log
(
kEpsilon
);
class_default_output_
[
0
]
=
-
std
::
log
(
kEpsilon
);
}
}
...
...
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