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
7dca0bb2
"include/git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "3400e3899d1c45997337bdbd0c8a2f729e805cbc"
Commit
7dca0bb2
authored
Jan 20, 2017
by
cbecker
Committed by
Guolin Ke
Jan 20, 2017
Browse files
Add `feature_infos` to LoadModelFromString() (#239)
parent
7426ac3c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
src/boosting/gbdt.cpp
src/boosting/gbdt.cpp
+40
-0
No files found.
src/boosting/gbdt.cpp
View file @
7dca0bb2
...
@@ -615,6 +615,46 @@ bool GBDT::LoadModelFromString(const std::string& model_str) {
...
@@ -615,6 +615,46 @@ bool GBDT::LoadModelFromString(const std::string& model_str) {
return
false
;
return
false
;
}
}
// returns offset, or lines.size() if not found.
auto
find_string_lineno
=
[
&
lines
](
const
std
::
string
&
str
,
size_t
start_line
=
0
)
{
size_t
i
=
start_line
;
size_t
featinfo_find_pos
=
std
::
string
::
npos
;
while
(
i
<
lines
.
size
())
{
featinfo_find_pos
=
lines
[
i
].
find
(
str
);
if
(
featinfo_find_pos
!=
std
::
string
::
npos
)
break
;
++
i
;
}
return
i
;
};
// load feature information
{
size_t
finfo_line_idx
=
find_string_lineno
(
"feature information:"
);
if
(
finfo_line_idx
>=
lines
.
size
())
{
Log
::
Fatal
(
"Model file doesn't contain feature information"
);
return
false
;
}
feature_infos_
.
resize
(
max_feature_idx_
+
1
);
// search for each feature name
for
(
int
i
=
0
;
i
<
max_feature_idx_
+
1
;
i
++
)
{
const
auto
feat_name
=
feature_names_
[
i
];
size_t
line_idx
=
find_string_lineno
(
feat_name
+
"="
,
finfo_line_idx
+
1
);
if
(
line_idx
>=
lines
.
size
())
{
Log
::
Fatal
((
"Model file doesn't contain feature information for feature "
+
feat_name
).
c_str
());
return
false
;
}
const
auto
this_line
=
lines
[
line_idx
];
feature_infos_
[
i
]
=
this_line
.
substr
((
feat_name
+
"="
).
size
());
}
}
// get tree models
// get tree models
size_t
i
=
0
;
size_t
i
=
0
;
while
(
i
<
lines
.
size
())
{
while
(
i
<
lines
.
size
())
{
...
...
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