Medial Code Documentation
Loading...
Searching...
No Matches
categorical_helpers.h
1
6#include <numeric>
7#include <vector>
8
9#include "xgboost/span.h"
10#include "helpers.h"
11#include "../../src/common/categorical.h"
12
13namespace xgboost {
14inline std::vector<float> OneHotEncodeFeature(std::vector<float> x,
15 size_t num_cat) {
16 std::vector<float> ret(x.size() * num_cat, 0);
17 size_t n_rows = x.size();
18 for (size_t r = 0; r < n_rows; ++r) {
19 bst_cat_t cat = common::AsCat(x[r]);
20 ret.at(num_cat * r + cat) = 1;
21 }
22 return ret;
23}
24
25} // namespace xgboost
namespace of xgboost
Definition base.h:90
int32_t bst_cat_t
Categorical value type.
Definition base.h:99