我正在使用 python
中的 scikit learn
库,我想在使用 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
是一个包含每个类别权重的 float 列表。有办法解决这个问题吗?
最佳答案
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
)
类似的东西适用于我的代码。
关于python - 如何在RandomizedSearchCV中使用样本加权?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24617141/