Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Machine learning 在安装CATBoostregrestor时,我可以在评估集中设置观察值的权重吗?_Machine Learning_Catboost - Fatal编程技术网

Machine learning 在安装CATBoostregrestor时,我可以在评估集中设置观察值的权重吗?

Machine learning 在安装CATBoostregrestor时,我可以在评估集中设置观察值的权重吗?,machine-learning,catboost,Machine Learning,Catboost,我正在尝试使用train集合和eval集合来拟合a。有一个参数,sample\u weight,用于对train\u集合中的观察值进行加权,但我看不到与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

我正在尝试使用
train
集合和
eval
集合来拟合a。有一个参数,
sample\u weight
,用于对
train\u集合
中的观察值进行加权,但我看不到与
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)