Skip to content

Commit cb46ff3

Browse files
committed
work on test.
1 parent 2abf782 commit cb46ff3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/python/test_eval_metrics.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,26 @@ def run_pr_auc_ltr(self, tree_method):
317317
def test_pr_auc_ltr(self):
318318
self.run_pr_auc_ltr("hist")
319319

320+
def test_precision_score(self):
321+
from sklearn.metrics import precision_score
322+
from sklearn.datasets import make_classification
323+
324+
x, y = make_classification(n_samples=128, n_features=4, n_classes=2)
325+
qid = np.zeros(shape=y.shape) # same group
326+
327+
ltr = xgb.XGBRanker()
328+
ltr.fit(x, y, qid=qid)
329+
p = ltr.predict(x)
330+
sorted_idx = np.argsort(p)
331+
332+
score_0 = precision_score(y, y[sorted_idx])
333+
print(score_0)
334+
335+
Xy = xgb.DMatrix(x, y)
336+
ltr.set_params(eval_metric="pre")
337+
e = ltr.get_booster().eval_set(evals=[(Xy, "Xy")])
338+
print(e)
339+
320340
@pytest.mark.skipif(**tm.no_sklearn())
321341
def test_quantile_error(self) -> None:
322342
check_quantile_error("hist")

0 commit comments

Comments
 (0)