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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM