class_weigths 在 lib scikit 的分类中,python

class_weigths in claserization in lib scikit, python

我是 scikit 的新手,所以这是一个简单的问题

我已经尝试将 class_weigths 参数与 dict 类型传递给分类,如 sklearn.svm.SVC

有人能给我一个正确的参数字典的例子吗,我尝试使用 model.class_weight = dict(zero=100, one=1) 但在 SVM 中它给出了 :

TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'

在其他方法中我没有效果:(

我不太清楚你为什么要用字符串调用字典的键。根据 the documentation and this 示例,您希望键代表 类 的索引。也就是说,您希望它们是整数!

根据上面 link 中的示例,他们使用以下权重实例化 SVM(同样,使用整数索引 类):

wclf = svm.SVC(kernel='linear', class_weight={1: 10})

以您的示例为例,您需要使用

model.class_weight = {0:100, 1:1}