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
011fe024
Commit
011fe024
authored
Jan 14, 2017
by
Guolin Ke
Browse files
output more feature information in model file, #192
parent
9fd5bc25
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
2 deletions
+42
-2
include/LightGBM/bin.h
include/LightGBM/bin.h
+22
-1
src/boosting/gbdt.cpp
src/boosting/gbdt.cpp
+16
-0
src/boosting/gbdt.h
src/boosting/gbdt.h
+2
-0
src/io/bin.cpp
src/io/bin.cpp
+2
-1
No files found.
include/LightGBM/bin.h
View file @
011fe024
#ifndef LIGHTGBM_BIN_H_
#define LIGHTGBM_BIN_H_
#include <LightGBM/utils/common.h>
#include <LightGBM/meta.h>
#include <vector>
#include <functional>
#include <unordered_map>
#include <sstream>
namespace
LightGBM
{
...
...
@@ -150,8 +153,22 @@ public:
* \param buffer The source
*/
void
CopyFrom
(
const
char
*
buffer
);
/*!
* \brief Get bin types
*/
inline
BinType
bin_type
()
const
{
return
bin_type_
;
}
/*!
* \brief Get bin info
*/
inline
std
::
string
bin_info
()
const
{
if
(
bin_type_
==
BinType
::
CategoricalBin
)
{
return
Common
::
Join
(
bin_2_categorical_
,
","
);
}
else
{
std
::
stringstream
str_buf
;
str_buf
<<
'['
<<
min_val_
<<
','
<<
max_val_
<<
']'
;
return
str_buf
.
str
();
}
}
private:
/*! \brief Number of bins */
int
num_bin_
;
...
...
@@ -167,6 +184,10 @@ private:
std
::
unordered_map
<
int
,
unsigned
int
>
categorical_2_bin_
;
/*! \brief Mapper from bin to categorical */
std
::
vector
<
int
>
bin_2_categorical_
;
/*! \brief minimal feature vaule */
double
min_val_
;
/*! \brief maximum feature value */
double
max_val_
;
};
/*!
...
...
src/boosting/gbdt.cpp
View file @
011fe024
...
...
@@ -109,6 +109,16 @@ void GBDT::ResetTrainingData(const BoostingConfig* config, const Dataset* train_
label_idx_
=
train_data
->
label_idx
();
// get feature names
feature_names_
=
train_data
->
feature_names
();
// get feature infos
feature_infos_
.
clear
();
for
(
int
i
=
0
;
i
<
max_feature_idx_
+
1
;
++
i
)
{
int
feature_idx
=
train_data
->
GetInnerFeatureIndex
(
i
);
if
(
feature_idx
<
0
)
{
feature_infos_
.
push_back
(
"trival feature"
);
}
else
{
feature_infos_
.
push_back
(
train_data
->
FeatureAt
(
feature_idx
)
->
bin_mapper
()
->
bin_info
());
}
}
}
if
((
train_data_
!=
train_data
&&
train_data
!=
nullptr
)
...
...
@@ -536,6 +546,12 @@ void GBDT::SaveModelToFile(int num_iteration, const char* filename) const {
for
(
size_t
i
=
0
;
i
<
pairs
.
size
();
++
i
)
{
output_file
<<
pairs
[
i
].
second
<<
"="
<<
std
::
to_string
(
pairs
[
i
].
first
)
<<
std
::
endl
;
}
output_file
<<
std
::
endl
<<
"feature information:"
<<
std
::
endl
;
for
(
size_t
i
=
0
;
i
<
max_feature_idx_
+
1
;
++
i
)
{
output_file
<<
feature_names_
[
i
]
<<
"="
<<
feature_infos_
[
i
]
<<
std
::
endl
;
}
output_file
.
close
();
}
...
...
src/boosting/gbdt.h
View file @
011fe024
...
...
@@ -318,6 +318,8 @@ protected:
int
num_init_iteration_
;
/*! \brief Feature names */
std
::
vector
<
std
::
string
>
feature_names_
;
/*! \brief Feature informations */
std
::
vector
<
std
::
string
>
feature_infos_
;
/*! \brief number of threads */
int
num_threads_
;
/*! \brief Buffer for multi-threading bagging */
...
...
src/io/bin.cpp
View file @
011fe024
...
...
@@ -83,7 +83,8 @@ void BinMapper::FindBin(std::vector<double>* values, size_t total_sample_cnt, in
distinct_values
.
push_back
(
0
);
counts
.
push_back
(
zero_cnt
);
}
min_val_
=
distinct_values
.
front
();
max_val_
=
distinct_values
.
back
();
int
num_values
=
static_cast
<
int
>
(
distinct_values
.
size
());
int
cnt_in_bin0
=
0
;
if
(
bin_type_
==
BinType
::
NumericalBin
)
{
...
...
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