XGBRanker:无法将qid用作拟合参数

2024-09-28 21:02:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用XGBoost.XGBRanker构建一个排名模型

(数据集为mslr web-10k,折叠1)

我已经将fold 1 train.txt转换为熊猫数据帧,现在我正在尝试复制XGBRanker模型。我不确定如何有效地导出.fit方法的“group”参数,但文档中明确指出:

Query group information is required for ranking tasks by either using the group parameter or qid parameter in fit method.

Before fitting the model, your data need to be sorted by query group. When fitting the model, you need to provide an additional array that contains the size of each query group.

For example, if your original data look like:

qid

label

features

1

0

x_1

1

1

x_2

1

0

x_3

2

0

x_4

2

1

x_5

2

1

x_6

2

1

x_7

then your group array should be [3, 4]. Sometimes using query id (qid) instead of group can be more convenient.

在这里,我尝试适合模型:

X = np.array(df.drop(columns = ['label', 'query_id']))
y = np.array(df['label'])
qid = np.array(df['query_id'])
scaler = StandardScaler()
scaler.fit(X)

model = XGB.XGBRanker(verbosity = 3, n_jobs = -1, learning_rate = 0.1, subsample = 0.5, n_estimators = 1000)
model.fit(X, y, group = None, qid = qid)

但是我得到了以下错误

fit() got an unexpected keyword argument 'qid'

文件是here。(可能需要对“XGBRanker”按ctrl+f组合键)

有人能告诉我我做错了什么吗?或者如何导出正确的组数组


Tags: the模型iddfyourmodelnpgroup