如何在RandomizedSearchCV中使用样本加权?
我正在使用 scikit learn
库来进行 python
编程,我想在使用 RandomizedSearchCV 进行交叉验证时给每个样本加权。当我尝试运行以下代码时:
search = RandomizedSearchCV(estimator, param_distributions,
n_iter=args.iterations,
scoring=mae_scorer, n_jobs=8, refit=True,
cv=KFold(X_train.shape[0], 10, shuffle=True,
random_state=args.seed), verbose=1,
random_state=args.seed,
fit_params={'sample_weight': sample_weight})
出现了以下错误:
AttributeError: 'list' object has no attribute 'copy'
值得一提的是,sample_weight
是一个包含每个类别权重的浮点数列表。有没有什么办法可以解决这个问题?
1 个回答
0
search = RandomizedSearchCV(estimator, param_distributions,
n_iter=args.iterations,
scoring=mae_scorer, n_jobs=8, refit=True,
cv=KFold(X_train.shape[0], 10, shuffle=True,
random_state=args.seed), verbose=1,
random_state=args.seed
)
search.fit(X_train, np.ravel(y_train)
,sample_weight=our_sample_weight
)
我的代码里有类似这样的东西可以正常工作。