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