16#include "xgboost/json.h"
25 uint32_t deprecated_num_feature;
27 int32_t deprecated_num_output_group;
32 static_assert(
sizeof(*this) ==
sizeof(int32_t) * 34,
33 "Model parameter size can not be changed.");
38 DMLC_DECLARE_FIELD(deprecated_num_feature);
39 DMLC_DECLARE_FIELD(deprecated_num_output_group);
50 int32_t num_boosted_rounds{0};
55 : learner_model_param{learner_model_param} {}
56 void Configure(Args
const &) { }
59 std::vector<bst_float> weight;
61 inline void LazyInitModel() {
62 if (!weight.empty()) {
66 weight.resize((learner_model_param->
num_feature + 1) *
68 std::fill(weight.begin(), weight.end(), 0.0f);
76 fo->Write(¶m_,
sizeof(param_));
81 CHECK_EQ(fi->Read(¶m_,
sizeof(param_)),
sizeof(param_));
98 inline const bst_float *operator[](
size_t i)
const {
102 std::vector<std::string> DumpModel(
const FeatureMap &,
bool,
103 std::string format)
const {
105 const unsigned nfeature = learner_model_param->
num_feature;
107 std::stringstream fo(
"");
108 if (format ==
"json") {
109 fo <<
" { \"bias\": [" << std::endl;
110 for (
int gid = 0; gid < ngroup; ++gid) {
112 fo <<
"," << std::endl;
114 fo <<
" " << this->Bias()[gid];
117 <<
" ]," << std::endl
118 <<
" \"weight\": [" << std::endl;
119 for (
unsigned i = 0; i < nfeature; ++i) {
120 for (
int gid = 0; gid < ngroup; ++gid) {
121 if (i != 0 || gid != 0) {
122 fo <<
"," << std::endl;
124 fo <<
" " << (*this)[i][gid];
127 fo << std::endl <<
" ]" << std::endl <<
" }";
130 for (
int gid = 0; gid < ngroup; ++gid) {
131 fo << this->Bias()[gid] << std::endl;
134 for (
unsigned i = 0; i < nfeature; ++i) {
135 for (
int gid = 0; gid < ngroup; ++gid) {
136 fo << (*this)[i][gid] << std::endl;
140 std::vector<std::string> v;
141 v.push_back(fo.str());
interface of stream I/O for serialization
Definition io.h:30
Feature map data structure to help text model dump. TODO(tqchen) consider make it even more lightweig...
Definition feature_map.h:22
Data structure representing JSON format.
Definition json.h:357
Definition gblinear_model.h:44
void SaveModel(Json *p_out) const override
saves the model config to a JSON object
Definition gblinear_model.cc:13
void LoadModel(Json const &in) override
load the model from a JSON object
Definition gblinear_model.cc:23
defines serializable interface of dmlc
Provide lightweight util to do parameter setup and checking.
Feature map data structure to help visualization and model dump.
Copyright 2015-2023 by XGBoost Contributors.
macro for using C++11 enum class as DMLC parameter
Copyright 2015-2023 by XGBoost Contributors.
Defines the abstract interface for different components in XGBoost.
namespace of xgboost
Definition base.h:90
float bst_float
float type, used for storing statistics
Definition base.h:97
Basic model parameters, used to describe the booster.
Definition learner.h:291
std::uint32_t num_output_group
The number of classes or targets.
Definition learner.h:307
bst_feature_t num_feature
The number of features.
Definition learner.h:303
Definition gblinear_model.h:23