我可以在拟合 CatBoostRegressor 时对评估集中的观察值进行加权吗?

Can I weight of observations in the evaluation set while fitting a CatBoostRegressor?

我正在尝试使用 train 集和 eval 集来拟合 CatBoostRegressor。有一个参数 sample_weight 来加权 train_set 中的观察值,但我看不到 eval 集的等效项。

这是一个例子:

from catboost import CatBoostRegressor

# Initialize data
cat_features = [0,1,2]

x_train = [["a","b",1,4,5,6],["a","b",4,5,6,7],["c","d",30,40,50,60]]
x_eval = [["a","b",2,4,6,8],["a","d",1,4,50,60]]

y_train = [10,20,30]
y_eval = [10,20]

w_train = [0.1, 0.2, 0.7]
w_eval = [0.1, 0.2]

# Initialize CatBoostRegressor
model = CatBoostRegressor(iterations=2, learning_rate=1, depth=2)

# Fit model
model.fit(X=x_train,
          y=y_train,
          sample_weight=w_train,
          eval_set=(x_eval, y_eval),
          cat_features=cat_features)

示例中 w_eval 的正确位置在哪里?

是的,为此您需要使用 Pool class。 示例:

from catboost import CatBoostClassifier, Pool

train_data = Pool(
    data=[[1, 4, 5, 6], 
          [4, 5, 6, 7], 
          [30, 40, 50, 60]],
    label=[1, 1, -1],
    weight=[0.1, 0.2, 0.3]
)

eval_data = Pool(
    data=[[1, 4, 5, 6], 
          [4, 5, 6, 7], 
          [30, 40, 50, 60]],
    label=[1, 0, -1],
    weight=[0.7, 0.1, 0.3]
)

model = CatBoostClassifier(iterations = 10)

model.fit(X=train_data, eval_set=eval_data)