gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:44:32 35 4
gpt4 key购买 nike

我正在尝试适应 CatBoostRegressor ,同时使用train集和eval集。有一个参数 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 类。示例:

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)

关于machine-learning - 我可以在拟合 CatBoostRegressor 时对评估集中的观测值进行加权吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54198009/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com