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
614f69d4
Unverified
Commit
614f69d4
authored
Jul 08, 2018
by
Guolin Ke
Committed by
GitHub
Jul 08, 2018
Browse files
fix load parameter (#1495)
parent
c948194d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
src/boosting/gbdt.h
src/boosting/gbdt.h
+2
-0
src/boosting/gbdt_model_text.cpp
src/boosting/gbdt_model_text.cpp
+27
-2
No files found.
src/boosting/gbdt.h
View file @
614f69d4
...
@@ -456,8 +456,10 @@ protected:
...
@@ -456,8 +456,10 @@ protected:
std
::
unique_ptr
<
ObjectiveFunction
>
loaded_objective_
;
std
::
unique_ptr
<
ObjectiveFunction
>
loaded_objective_
;
bool
average_output_
;
bool
average_output_
;
bool
need_re_bagging_
;
bool
need_re_bagging_
;
std
::
string
loaded_parameter_
;
Json
forced_splits_json_
;
Json
forced_splits_json_
;
};
};
}
// namespace LightGBM
}
// namespace LightGBM
...
...
src/boosting/gbdt_model_text.cpp
View file @
614f69d4
...
@@ -280,6 +280,7 @@ std::string GBDT::SaveModelToString(int num_iteration) const {
...
@@ -280,6 +280,7 @@ std::string GBDT::SaveModelToString(int num_iteration) const {
ss
<<
tree_strs
[
i
];
ss
<<
tree_strs
[
i
];
tree_strs
[
i
].
clear
();
tree_strs
[
i
].
clear
();
}
}
ss
<<
"end of trees"
<<
"
\n
"
;
std
::
vector
<
double
>
feature_importances
=
FeatureImportance
(
num_iteration
,
0
);
std
::
vector
<
double
>
feature_importances
=
FeatureImportance
(
num_iteration
,
0
);
// store the importance first
// store the importance first
...
@@ -301,8 +302,13 @@ std::string GBDT::SaveModelToString(int num_iteration) const {
...
@@ -301,8 +302,13 @@ std::string GBDT::SaveModelToString(int num_iteration) const {
ss
<<
pairs
[
i
].
second
<<
"="
<<
std
::
to_string
(
pairs
[
i
].
first
)
<<
'\n'
;
ss
<<
pairs
[
i
].
second
<<
"="
<<
std
::
to_string
(
pairs
[
i
].
first
)
<<
'\n'
;
}
}
if
(
config_
!=
nullptr
)
{
if
(
config_
!=
nullptr
)
{
ss
<<
"parameters:"
<<
'\n'
;
ss
<<
"
\n
parameters:"
<<
'\n'
;
ss
<<
config_
->
ToString
()
<<
"
\n
"
;
ss
<<
config_
->
ToString
()
<<
"
\n
"
;
ss
<<
"end of parameters"
<<
'\n'
;
}
else
if
(
!
loaded_parameter_
.
empty
())
{
ss
<<
"
\n
parameters:"
<<
'\n'
;
ss
<<
loaded_parameter_
<<
"
\n
"
;
ss
<<
"end of parameters"
<<
'\n'
;
}
}
return
ss
.
str
();
return
ss
.
str
();
}
}
...
@@ -465,7 +471,26 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) {
...
@@ -465,7 +471,26 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) {
num_iteration_for_pred_
=
static_cast
<
int
>
(
models_
.
size
())
/
num_tree_per_iteration_
;
num_iteration_for_pred_
=
static_cast
<
int
>
(
models_
.
size
())
/
num_tree_per_iteration_
;
num_init_iteration_
=
num_iteration_for_pred_
;
num_init_iteration_
=
num_iteration_for_pred_
;
iter_
=
0
;
iter_
=
0
;
bool
is_inparameter
=
false
;
std
::
stringstream
ss
;
while
(
p
<
end
)
{
auto
line_len
=
Common
::
GetLine
(
p
);
std
::
string
cur_line
(
p
,
line_len
);
if
(
line_len
>
0
)
{
if
(
cur_line
==
std
::
string
(
"parameters:"
))
{
is_inparameter
=
true
;
}
else
if
(
cur_line
==
std
::
string
(
"end of parameters"
))
{
break
;
}
else
if
(
is_inparameter
)
{
ss
<<
cur_line
<<
"
\n
"
;
}
}
p
+=
line_len
;
p
=
Common
::
SkipNewLine
(
p
);
}
if
(
!
ss
.
str
().
empty
())
{
loaded_parameter_
=
ss
.
str
();
}
return
true
;
return
true
;
}
}
...
...
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