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

Function make_example_data

demo/guide-python/cat_pipeline.py:34–55  ·  view source on GitHub ↗

Generate data for demo.

()

Source from the content-addressed store, hash-verified

32
33
34def make_example_data() -> Tuple[pd.DataFrame, pd.Series, List[str]]:
35 """Generate data for demo."""
36 n_samples = 2048
37 rng = np.random.default_rng(1994)
38
39 # We have three categorical features, while the rest are numerical.
40 categorical_features = ["brand_id", "retailer_id", "category_id"]
41
42 df = pd.DataFrame(
43 np.random.randint(32, 96, size=(n_samples, 3)),
44 columns=categorical_features,
45 )
46
47 df["price"] = rng.integers(100, 200, size=(n_samples,))
48 df["stock_status"] = rng.choice([True, False], n_samples)
49 df["on_sale"] = rng.choice([True, False], n_samples)
50 df["label"] = rng.normal(loc=0.0, scale=1.0, size=n_samples)
51
52 X = df.drop(["label"], axis=1)
53 y = df["label"]
54
55 return X, y, categorical_features
56
57
58def native() -> None:

Callers 2

nativeFunction · 0.85
pipelineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected