我想在sklearn中为BaggingClassifier使用不同的权重。 对于值为1,2,3的类型,我需要重量为1,30,30和30。 http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.BaggingClassifier.html#sklearn.ensemble.BaggingClassifier.fit
这是我的代码:
sample_weight=[1,30,30,30]
bagging.fit(XTrain,yTrain,sample_weight)
这不起作用。你能指导我一下正确的格式吗?
基于此处给出的帮助,我做了以下事情:
bagging.fit(XTrain,yTrain,sample_weight=w)
和w形状为('w.shape', (417, 1))
和('XTrain.shape', (417, 7))
,yTrain.shape (417,)
我收到以下错误:ValueError: could not broadcast input array from shape (417,417) into shape (417,1)
答案 0 :(得分:0)
sample_weight
XTrain
的形状必须为equal to the number of items
sample_weight : array-like, shape = [n_samples] or None
但请注意:
样本权重。如果为None,则样本的权重相等。请注意,仅当基本估算器支持样本权重时才支持此功能。