compute_class_weight() takes 1 positional argument but 3 were given

调用sklearn的compute_class_weight提示错误”compute_class_weight() takes 1 positional argument but 3 were given“,解决办法为函数里加上参数名:
from sklearn.utils.class_weight import compute_class_weight

label = [0] * 9 + [1] * 1 + [2, 2]
classes = [0, 1, 2]
weight = compute_class_weight(class_weight='balanced', classes=classes, y=label)
print(weight)

参考链接:Compute class weight function issue in 'sklearn' library when used in 'Keras' classification (Python 3.8, only in VS code) - Stack Overflow
posted @ 2021-11-15 11:35  夏天的冰棍儿  阅读(4545)  评论(0编辑  收藏  举报