[doc] Fix learning to rank tutorial. [skip ci] (#10539)

This commit is contained in:
Jiaming Yuan 2024-07-03 22:52:26 +08:00 committed by GitHub
parent 6243e7c43d
commit cd1d108c7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -72,8 +72,11 @@ Please note that, as of writing, there's no learning-to-rank interface in scikit
.. code-block:: python .. code-block:: python
import pandas as pd import pandas as pd
# `X`, `qid`, and `y` are from the previous snippet, they are all sorted by the `sorted_idx`.
df = pd.DataFrame(X, columns=[str(i) for i in range(X.shape[1])]) df = pd.DataFrame(X, columns=[str(i) for i in range(X.shape[1])])
df["qid"] = qid[sorted_idx] df["qid"] = qid
ranker.fit(df, y) # No need to pass qid as a separate argument ranker.fit(df, y) # No need to pass qid as a separate argument
from sklearn.model_selection import StratifiedGroupKFold, cross_val_score from sklearn.model_selection import StratifiedGroupKFold, cross_val_score