MCPcopy Create free account
hub / github.com/dmlc/xgboost / _basic_example

Function _basic_example

python-package/xgboost/testing/ordinal.py:304–319  ·  view source on GitHub ↗
(device: Device)

Source from the content-addressed store, hash-verified

302
303
304def _basic_example(device: Device) -> Tuple[Any, Any, np.ndarray, np.ndarray]:
305 Df, _ = get_df_impl(device)
306
307 enc = Df({"c": ["cdef", "abc", "def"]}, dtype="category")
308 codes = enc.c.cat.codes # 1, 0, 2
309 assert_allclose(device, asarray(device, codes), np.array([1, 0, 2]))
310 encoded = np.array([codes.iloc[2], codes.iloc[1]]) # def, abc
311 np.testing.assert_allclose(encoded, [2, 0])
312
313 reenc = Df({"c": ["def", "abc"]}, dtype="category") # same as `encoded`
314 codes = reenc.c.cat.codes
315 assert_allclose(device, codes, np.array([1, 0]))
316
317 y = np.array([0, 1, 2])
318
319 return enc, reenc, encoded, y
320
321
322def run_basic_predict(DMatrixT: Type, device: Device, tdevice: Device) -> None:

Callers 2

run_basic_predictFunction · 0.85
_run_predtFunction · 0.85

Calls 3

get_df_implFunction · 0.85
assert_allcloseFunction · 0.85
asarrayFunction · 0.85

Tested by

no test coverage detected