add dump to linear model

This commit is contained in:
tqchen 2014-12-24 02:56:32 -08:00
parent 6d7ef172ef
commit c8f422b3b9

View File

@ -8,6 +8,7 @@
*/ */
#include <vector> #include <vector>
#include <string> #include <string>
#include <sstream>
#include <algorithm> #include <algorithm>
#include "./gbm.h" #include "./gbm.h"
#include "../tree/updater.h" #include "../tree/updater.h"
@ -142,8 +143,20 @@ class GBLinear : public IGradBooster {
utils::Error("gblinear does not support predict leaf index"); utils::Error("gblinear does not support predict leaf index");
} }
virtual std::vector<std::string> DumpModel(const utils::FeatMap& fmap, int option) { virtual std::vector<std::string> DumpModel(const utils::FeatMap& fmap, int option) {
utils::Error("gblinear does not support dump model"); std::stringstream fo("");
return std::vector<std::string>(); fo << "bias:\n";
for (int i = 0; i < model.param.num_output_group; ++i) {
fo << model.bias()[i] << std::endl;
}
fo << "weight:\n";
for (int i = 0; i < model.param.num_output_group; ++i) {
for (int j = 0; j <model.param.num_feature; ++j) {
fo << model[i][j] << std::endl;
}
}
std::vector<std::string> v;
v.push_back(fo.str());
return v;
} }
protected: protected: