- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将我拥有的数据集拆分为测试/训练,同时确保分类标签在测试/训练中的分布相同。为此,我使用了分层选项,但它会引发如下错误:
X_full_train, X_full_test, Y_full_train, Y_full_test = train_test_split(X_values_full, Y_values, test_size = 0.33, random_state = 42, stratify = True)
错误信息:
TypeError Traceback (most recent call last)
in
19
20
---> 21 X_full_train, X_full_test, Y_full_train, Y_full_test = train_test_split(X_values_full, Y_values, test_size = 0.33, random_state = 42, stratify = True)
22
23
~/anaconda3/lib/python3.8/site-packages/sklearn/model_selection/_split.py in train_test_split(*arrays, **options)
2150 random_state=random_state)
2151
-> 2152 train, test = next(cv.split(X=arrays[0], y=stratify))
2153
2154 return list(chain.from_iterable((_safe_indexing(a, train),
~/anaconda3/lib/python3.8/site-packages/sklearn/model_selection/_split.py in split(self, X, y, groups)
1744 to an integer.
1745 """
-> 1746 y = check_array(y, ensure_2d=False, dtype=None)
1747 return super().split(X, y, groups)
1748
~/anaconda3/lib/python3.8/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs)
71 FutureWarning)
72 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 73 return f(**kwargs)
74 return inner_f
75
~/anaconda3/lib/python3.8/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator)
647
648 if ensure_min_samples > 0:
--> 649 n_samples = _num_samples(array)
650 if n_samples < ensure_min_samples:
651 raise ValueError("Found array with %d sample(s) (shape=%s) while a"
~/anaconda3/lib/python3.8/site-packages/sklearn/utils/validation.py in _num_samples(x)
194 if hasattr(x, 'shape') and x.shape is not None:
195 if len(x.shape) == 0:
--> 196 raise TypeError("Singleton array %r cannot be considered"
197 " a valid collection." % x)
198 # Check that shape is returning an integer or default to len
TypeError: Singleton array array(True) cannot be considered a valid collection.
当我尝试在没有分层选项的情况下执行此操作时,它不会给我错误。 我认为这是因为我的 Y 标签没有在测试/训练之间均匀分布标签所需的最少样本数,但是:
pp.pprint(Counter(Y_values))
给出:
Counter({13: 1084,
1: 459,
7: 364,
8: 310,
38: 295,
15: 202,
4: 170,
37: 105,
3: 98,
0: 85,
24: 79,
20: 78,
35: 76,
2: 75,
12: 74,
39: 72,
22: 71,
9: 63,
26: 59,
11: 55,
18: 55,
32: 53,
19: 53,
33: 53,
5: 52,
30: 42,
29: 42,
25: 41,
10: 39,
23: 38,
21: 38,
6: 38,
27: 37,
14: 36,
36: 36,
34: 34,
28: 33,
17: 31,
31: 30,
16: 30})
最佳答案
stratifyarray-like, default=None If not None, data is split in astratified fashion, using this as the class labels.
boolean
值如
True
或
False
,但类标签自己。
X_full_train, X_full_test, Y_full_train, Y_full_test = train_test_split(X_values_full, Y_values, test_size = 0.33, random_state = 42, stratify = True)
到:
X_full_train, X_full_test, Y_full_train, Y_full_test = train_test_split(X_values_full, Y_values, test_size = 0.33, random_state = 42, stratify = Y_values)
关于python - 类型错误 : Singleton array array(True) cannot be considered a valid collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63851453/
我在我的项目中运行 pylint 进行错误检测,并偶然发现了这个警告。 我该如何解决这个警告? 最佳答案 假设您正在打开一个文件: file_handle = open("some_file.txt"
我们都知道 Jquery 有很多好处。如果您在企业中使用过Jquery,您的“学习”经历是什么?; 为了改进和利用 Jquery 的优势,需要考虑向后兼容性、与现有 javascript 的冲突、CS
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 4 年前。 Improve
我想用 div 模拟表格的行为。 我的布局结构分为三列: div#wrapper { width:800px; float:left; height:100%; margin-top:
给定一家软件公司,开发人员团队合作处理多个问题不同的项目。项目需要分配的特定技能开发商。出于我的目的,我想保持简单并将其限制为一个技能,即编程语言。所以有些项目需要Java,有些需要C 等 项目有固定
我正在使用两个函数 sprintf 和 snprintf 来处理“double”到字符串的转换,在其中一种情况下,正在运行的应用程序的语言环境与 Windows 的语言环境不同。因此,在这种情况下,s
我正在尝试实现一个 LocaleListener 来检测用户的首选语言(考虑 Accept-Language header )并将其存储在 session 中以避免每次请求都检查它。我开发了下面的代码
我正在尝试运行如下查询: MATCH (n:Type1)-[:relation1]->(:Type1)(:Type1)(:Type1)(:Type1)<-[:relation2]-(:Type2) W
嗨,我想知道在 JSP 中使用循环的行为 在foreach周围,集合的每个值都在内部 它显示四行还是三行?它是否每次都考虑相同的值(例如“1”)? 1 1 2 3 或 1 2 3
这里是 Rust 新手。当提供一个参数并在函数声明中将其保留为未使用时(例如,在学习 Rust 时...),编译器会警告该变量在范围内未使用的事实,并建议考虑在其前加下划线。这样做,警告就会消失。 w
同时关注 rustbyexample.com教程中,我输入了以下代码: impl fmt::Display for Structure { fn fmt(&self, f: &mut fmt:
以 void * 和其他指针类型作为参数的 C++ 多态函数:它是否被认为是有歧义的? 我担心,因为任何指针都可以转换为 void*,下面的 bar 的第二次调用是否会执行 void bar(void
所以我有一个程序可以在一行中从用户那里获取数字,例如: 2 1 2 3 4 第一个数字:2表示输出应该是2行2列的矩阵: 1 2 3 4 这就是我填充数组的方式: int dim; scanf("%d
我想在我的博客上做一些类似于 gmail 的“考虑包括” 建议的事情,但带有标签。 我正在考虑像这样存储标签集: 我想到了以下算法: //a blog post is published //it h
我想看看 stackoverflow 是否使用单独的插件来执行那些亮黄色的弹出窗口,上面写着“请考虑将此答案标记为已接受 或“请考虑添加评论以说明您为什么投了反对票” 这是为此使用了一个 jquery
我尝试构建 a pure CSS tree .我遇到了 block 之间水平线的问题(两个 block 在同一层)。我在以下 jsfiddles 中隔离了问题: https://jsfiddle.ne
我正在准备 Django 中的测试或测验。测验需要在一定的时间范围内完成。说 40 题 30 分钟。我总是可以在测试开始时启动时钟,然后在测验完成时计算时间。然而,在尝试过程中,可能会出现互联网连接中
在MSDN ,我找到了这句话: The result of a ?? operator is not considered to be a constant even if both its argu
我有一个项目,我启用了新的 Nullable reference type feature enable 现在让我们考虑这段代码 public class Foo { } var foo =
我正在编写一个应该可缓存的 Webpack 加载器。 documentation for this.cacheable说: A cacheable loader must have a determi
我是一名优秀的程序员,十分优秀!