使用stratifiedKFold进行分层交叉验证时候报错:ValueError: Supported target types are: ('binary', 'multiclass'). Got
最新推荐文章于 2023-03-01 00:43:17 发布
胖虎艾春辉
最新推荐文章于 2023-03-01 00:43:17 发布
ValueError Traceback (most recent call last)
<ipython-input-42-2ab744268d80> in <module>()
20 print('---------分割线--------------')
21 sfolder = StratifiedKFold(n_splits=4,random_state=0,shuffle=False)
---> 22 for train, test in sfolder.split(X,y):
23 print('Train: %s | test: %s' % (train, test))
24 print(" ")
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py in split(self, X, y, groups)
330 n_samples))
--> 332 for train, test in super(_BaseKFold, self).split(X, y, groups):
333 yield train, test
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py in split(self, X, y, groups)
93 X, y, groups = indexable(X, y, groups)
94 indices = np.arange(_num_samples(X))
---> 95 for test_index in self._iter_test_masks(X, y, groups):
96 train_index = indices[np.logical_not(test_index)]
97 test_index = indices[test_index]
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py in _iter_test_masks(self, X, y, groups)
633 def _iter_test_masks(self, X, y=None, groups=None):
--> 634 test_folds = self._make_test_folds(X, y)
635 for i in range(self.n_splits):
636 yield test_folds == i
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py in _make_test_folds(self, X, y)
587 raise ValueError(
588 'Supported target types are: {}. Got {!r} instead.'.format(
--> 589 allowed_target_types, type_of_target_y))
591 y = column_or_1d(y)
ValueError: Supported target types are: ('binary', 'multiclass'). Got 'continuous' instead.
-
问题描述使用stratifiedKFold进行分层交叉验证时候报错:ValueError: Supported target types are: (‘binary’, ‘multiclass’). Got ‘continuous’ instead.
-
问题解决方法,这种分层抽样要求target必须是整型的,所以我们需要检查我们的target
使用stratifiedKFold进行分层交叉验证时候报错:ValueError: Supported target types are: ('binary', 'multiclass'). Got
ValueError Traceback (most recent call last)<ipython-input-42-2ab744268d80> in <module>() 20 print('---------分割线--------------') 21 sfolder = Stra...
keras保存模型时,
使用的是m.save_weights,只保存了模型的权重而没有结构,直接
使用keras.models.load_model就会
报错。所以,可以重新构建相同结构的模型,(m.save_weights)
使用m.load_weights;或者如上m.save,keras.models.load_model。
参考:https://blog.csdn.net/nima1994/article/details/91045745
但是我的问题是:我导入的模型是别人的,如何直接导入只有权重没有结构的模型呢?
1、keras.models.load_model() 读取网络、权重
之前一直想可视化模型的注意力热力图,找到了gradcam算法,具体是调用keras-vis的库。但是一直调试一直报错很苦恼,前前后后搞了一个月才成功跑通,于是今天准备写个博客记录一下心路历程,也方便后来者参考,不必再浪费太多时间在debug上
问题描述:
在用预训练模型VGG16做base_model并finetune时,报如下错误:
ValueError: Unable to determine penultimate Conv or Pooling layer for layer_idx: 2
但是如果是自己定义的模型就可以正常输出。
看起来应该是一个找不到对应layer的错误。于是很自然
最近在OpenCV-Python接口中使用cv2.findContours()函数来查找检测物体的轮廓。
根据网上的 教程,Python OpenCV的轮廓提取函数会返回两个值,第一个为轮廓的点集,第二个是各层轮廓的索引。但是实际调用时我的程序报错了,错误内容如下:too many values to unpack (expected 2)
其实是接受返回值不符,如果你仅仅使用一个变量a去接受返回值,调用len(a),你会发现长度为3,也就是说这个函数实际上返回了三个值
第一个,也是最坑爹的一个,它返回了你所处理的图像
第二个,正是我们要找的,轮廓的点集
第三个,各层轮廓的索引
使用方式如下:
心比天高,仗剑走天涯,保持热爱,奔赴向梦想!低调,谦虚,自律,反思,成长,还算是比较正能量的博主,公益免费传播……内心特别想在AI界做出一些可以推进历史进程影响力的东西(兴趣使然,有点小情怀,也有点使命感呀)……
03-01
Supported target types are: ('
binary', '
multiclass').
Got 'continuous' instead.
排查原因,发现是因为我们执行的是回归问题,而
使用了
分层(
StratifiedKFold),这货是不支持回归,只支持分类问题,因为在写参数里面是不能假如这个,删去即可
ValueError:
Supported target types are: (‘
binary’, ‘
multiclass’).
Got ‘
multilabel-indicator’ instead.
在
使用StratifiedKFold进行交叉检验时
报错。
k
fold =
StratifiedKFold(n_splits=10, shuffle=True, random_state=42)
for train_index, test_index in k
fold.split(x, y):
使用lgb.cv时出现ValueError: Supported target types are: (‘binary’, ‘multiclass’). Got ‘continuous’ instead.
默认情况下,lightgbm.cv中的stratify参数是True。 根据the documentation:
stratified (bool, optional (default=True)) – Whether to perform stratified sampling.
但是stratify只