@@ -59,8 +59,9 @@ Many of the examples in this page use functionality from ``numpy``. To run the e
59
59
60
60
.. code :: python
61
61
62
- data = np.random.rand(500 , 10 ) # 500 entities, each contains 10 features
63
- label = np.random.randint(2 , size = 500 ) # binary target
62
+ rng = np.random.default_rng()
63
+ data = rng.uniform(size = (500 , 10 )) # 500 entities, each contains 10 features
64
+ label = rng.integers(low = 0 , high = 2 , size = (500 , )) # binary target
64
65
train_data = lgb.Dataset(data, label = label)
65
66
66
67
**To load a scipy.sparse.csr\_ matrix array into Dataset: **
@@ -139,15 +140,17 @@ It doesn't need to convert to one-hot encoding, and is much faster than one-hot
139
140
140
141
.. code :: python
141
142
142
- w = np.random.rand(500 , )
143
+ rng = np.random.default_rng()
144
+ w = rng.uniform(size = (500 , ))
143
145
train_data = lgb.Dataset(data, label = label, weight = w)
144
146
145
147
or
146
148
147
149
.. code :: python
148
150
149
151
train_data = lgb.Dataset(data, label = label)
150
- w = np.random.rand(500 , )
152
+ rng = np.random.default_rng()
153
+ w = rng.uniform(size = (500 , ))
151
154
train_data.set_weight(w)
152
155
153
156
And you can use ``Dataset.set_init_score() `` to set initial score, and ``Dataset.set_group() `` to set group/query data for ranking tasks.
@@ -249,7 +252,8 @@ A model that has been trained or loaded can perform predictions on datasets:
249
252
.. code :: python
250
253
251
254
# 7 entities, each contains 10 features
252
- data = np.random.rand(7 , 10 )
255
+ rng = np.random.default_rng()
256
+ data = rng.uniform(size = (7 , 10 ))
253
257
ypred = bst.predict(data)
254
258
255
259
If early stopping is enabled during training, you can get predictions from the best iteration with ``bst.best_iteration ``:
0 commit comments