I'm trying to fit a CatBoostRegressor, using both a train
set and an eval
set. There is a parameter, sample_weight
, to weight observations in the train_set
, but I see no equivalent for the eval
set.
Here is an example:
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)
Where is the right place to put w_eval
in the example?
Yes, to do that you need to use Pool class. Example:
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)