在安装CatBoostRegressor时,我可以在评估集中加权观测值吗?

时间:2019-01-15 11:33:32

标签: machine-learning catboost

我正在尝试同时使用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放在哪里?

1 个答案:

答案 0 :(得分:1)

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

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)