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

Function generate_classification_model

tests/python/generate_models.py:107–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

105
106
107def generate_classification_model() -> None:
108 print("Classification")
109 X, y = make_classification(
110 n_samples=kRows,
111 n_features=kCols,
112 random_state=2025,
113 n_classes=kClasses,
114 n_informative=4,
115 n_redundant=0,
116 )
117 w = np.random.default_rng(2025).uniform(size=X.shape[0])
118
119 data = xgboost.DMatrix(X, label=y, weight=w)
120 booster = xgboost.train(
121 {
122 "num_class": kClasses,
123 "tree_method": "hist",
124 "num_parallel_tree": kForests,
125 "max_depth": kMaxDepth,
126 },
127 num_boost_round=kRounds,
128 dtrain=data,
129 )
130 booster.save_model(booster_ubj("cls"))
131 booster.save_model(booster_json("cls"))
132
133 cls = xgboost.XGBClassifier(
134 tree_method="hist",
135 num_parallel_tree=kForests,
136 max_depth=kMaxDepth,
137 n_estimators=kRounds,
138 )
139 cls.fit(X, y, sample_weight=w)
140 cls.save_model(skl_ubj("cls"))
141 cls.save_model(skl_json("cls"))
142
143
144def generate_ranking_model() -> None:

Callers 1

generate_models.pyFile · 0.85

Calls 8

fitMethod · 0.95
booster_ubjFunction · 0.85
booster_jsonFunction · 0.85
skl_ubjFunction · 0.85
skl_jsonFunction · 0.85
DMatrixMethod · 0.45
trainMethod · 0.45
save_modelMethod · 0.45

Tested by

no test coverage detected