MCPcopy
hub / github.com/ddbourgin/numpy-ml / to_one_hot

Function to_one_hot

numpy_ml/trees/gbdt.py:7–15  ·  view source on GitHub ↗
(labels, n_classes=None)

Source from the content-addressed store, hash-verified

5
6
7def to_one_hot(labels, n_classes=None):
8 if labels.ndim > 1:
9 raise ValueError("labels must have dimension 1, but got {}".format(labels.ndim))
10
11 N = labels.size
12 n_cols = np.max(labels) + 1 if n_classes is None else n_classes
13 one_hot = np.zeros((N, n_cols))
14 one_hot[np.arange(N), labels] = 1.0
15 return one_hot
16
17
18class GradientBoostedDecisionTree:

Callers 1

fitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected