当前位置:网站首页>compute_ class_ weight() takes 1 positional argument but 3 were given
compute_ class_ weight() takes 1 positional argument but 3 were given
2022-07-27 11:47:00 【Xiao Chen who wants money】
call sklearn Of compute_class_weight Prompt error ”compute_class_weight() takes 1 positional argument but 3 were given“
This is because comput_class_weight It's best to bring keywords when passing in , Without keywords , It can be considered as having only one parameter , This is a sklearn The source code .
def compute_class_weight(class_weight, *, classes, y):
"""Estimate class weights for unbalanced datasets.
Parameters
----------
class_weight : dict, 'balanced' or None
If 'balanced', class weights will be given by
``n_samples / (n_classes * np.bincount(y))``.
If a dictionary is given, keys are classes and values
are corresponding class weights.
If None is given, the class weights will be uniform.
classes : ndarray
Array of the classes occurring in the data, as given by
``np.unique(y_org)`` with ``y_org`` the original class labels.
y : array-like of shape (n_samples,)
Array of original class labels per sample.
Returns
-------
class_weight_vect : ndarray of shape (n_classes,)
Array with class_weight_vect[i] the weight for i-th class.
References
----------
The "balanced" heuristic is inspired by
Logistic Regression in Rare Events Data, King, Zen, 2001.
"""Later, it was found that it was incoming y When it comes to parameters ,label yes 2 Dimensional ,label The dimension of is (1000,1) To turn it into (1000,) Can .
labels = np.zeros((200,1))
labels[0:2][0] = 1
classes = [0, 1]
weight = compute_class_weight(class_weight='balanced', classes=classes, y=label.reshape(-1)
print(weight)边栏推荐
- Moveit2 - 5. Scenario Planning
- TapNet: Multivariate Time Series Classification with Attentional Prototypical Network
- Difference between verification and calibration
- Synchronous use reference of the new version of data warehouse (for beginners)
- CH340模块无法识别/烧写不进的一种可能性
- 源码编译安装LAMP
- Database cli tool docker image
- The difference between microcomputer and single chip microcomputer
- Modelarts image classification and object detection
- 数据库 cli 工具 docker 镜像
猜你喜欢

Codeforces round #664C

Maker Hongmeng application development training notes 02

LNMP architecture setup (deploy discuz Forum)

Keil MDK compilation appears..\user\stm32f10x H (428): error: # 67: expected a "}" wrong solution

Principle of control system based on feedback rate

Could not load dynamic library ‘libcudnn.so.8‘;

第8章 多线程

为什么选择智能电视?

Adobe Audition提示 音频输入的采样率与输出设备不匹配——问题解决

Japan Fukushima waste dump safety monitoring agreement will recognize the "safety" of the sea discharge plan
随机推荐
Principle of PWM and generation of PWM wave
Why choose smart TV?
Could not load dynamic library ‘libcudnn.so.8‘;
Shell脚本文本三剑客之awk
Adobe Audition提示 音频输入的采样率与输出设备不匹配——问题解决
请教大佬们,请问用flink sink数据到mysql有事务控制吗?如果在一个checkpoint时
Arduino常见供电问题与解决
微商的差商近似
LAN SDN technology hard core insider 11 the key of cloud convergence CP -- hierarchical port binding
82.(cesium之家)cesium点在3d模型上运动
Beyond Compare 3 下一个差异段/向下搜索箭头 找不到了
Greek alphabet reading
剑指 Offer 笔记: T57 - II. 和为 s 的连续正数序列
(10) File contains
为什么TCP三次握手的时候ACK=Seq+1
Codeforces round #664C
w.r.t. ; i.e.;etc.;e.g.是什么意思
Detailed explanation of MATLAB S-function
Keil MDK compilation appears..\user\stm32f10x H (428): error: # 67: expected a "}" wrong solution
LeetCode 02: 剑指 Offer 58 - I. 翻转单词顺序(简单); T123. 验证回文串 ; T9. 回文数