- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
因此,我需要使用预定义的组生成测试/训练/验证拆分。我不想使用 LeavePGroupsOut 因为我需要根据我想要的百分比将数据分离到训练和验证集中。在GroupShuffleSplit的文档中,对于test_size
参数,是这样说的:
test_size : float, int, None, optional If float, should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the test split. If int, represents the absolute number of test samples. If None, the value is set to the complement of the train size. By default, the value is set to 0.2. The default will change in version 0.21. It will remain 0.2 only if train_size is unspecified, otherwise it will complement the specified train_size.
但是,事实并非如此,如以下代码所示:
tr, ts = next(GroupShuffleSplit(n_splits=1, test_size=3).split(TR_set, groups=tr_groups))
print(tr)
print(ts)
例如打印出:
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 28 29 30 31 32 33 34 35 36 37
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 91 92 93
99 101 102 103 104 105 106 107]
[ 26 27 89 90 94 95 96 97 98 100]
正如您在上面看到的,测试大小不是 3,而是大于 3。情况几乎总是如此。我检查了索引组。显然,如果test_size是一个整数,它代表的是测试组的绝对数量,而不是样本数。我认为该文档具有误导性。
此外,当 test_size 为 float 时,它大多不考虑指定的比率。这可能是由于组中的样本大小不相等,但必须有一个注释/警告来指定在不相等的组大小与 test_size 比率相结合的情况下它遵循什么样的行为。
tr, ts = next(GroupShuffleSplit(n_splits=1, test_size=0.1).split(TR_set, groups=tr_groups))
print(len(tr))
print(len(ts))
给出:
70
38
其中测试大小是整个集合的 35%(应该是 10%)。
所以,要么我遗漏了一些东西,要么文档只是错误的描述。
谢谢。
最佳答案
没有错误,但文档在某些地方不正确。我在 scikit-learn's github page 中打开了一个问题对于这个主题。
关于python - sklearn.model_selection.GroupShuffleSplit 不会按照预期产生分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54950675/
>>> import sklearn.model_selection.train_test_split Traceback (most recent call last): File "", li
在 probability calibration of classifiers来自scikit-learn,有一段关于train_test_split的代码我在文档中找不到解释。 centers =
我将 train_test_split 导入为: from sklearn.model_selection import train_test_split 并且给出了一个错误 cannot impor
我知道 sklearn.model_selection.cross_val_score 函数使用了一个 make_scorer() 函数,该函数返回一个对估计器输出进行评分的可调用函数。cross_v
我想在 GridSearchCV 中定义一个新的评分,正如这里所述 http://scikit-learn.org/stable/modules/model_evaluation.html#imple
我正在尝试从数据中进行线性回归,但是当我尝试以下操作时: from sklearn.model_selection import train_test_split from sklearn.linea
因此,我需要使用预定义的组生成测试/训练/验证拆分。我不想使用 LeavePGroupsOut 因为我需要根据我想要的百分比将数据分离到训练和验证集中。在GroupShuffleSplit的文档中,对
我正在尝试使用 train_test_split 函数并编写: from sklearn.model_selection import train_test_split 这会导致 ImportErro
当我想使用sklearn.model_selection.train_test_split来分割训练集和测试集时,它会引发如下错误: AttributeError: module 'sklearn'
我正在制作一个具有不平衡类(比例为 1:10)的二元分类器。我尝试了 KNN、RF 和 XGB 分类器。我从 XGB 分类器中获得了最佳的精确召回权衡和 F1 分数(可能是因为数据集的大小非常小 -
我正在尝试运行 this example从 sklearn 更好地理解他们的 TfidfTransformer 来自 sklearn.feature_extraction.text。但是,我返回了 T
我正在尝试通过 Python 中的 Keras 深度学习库学习神经网络。我正在使用 Python 3 并引用此链接:Tutorial Link 我尝试运行下面的代码,但出现以下错误: 导入错误:没有名
我在做this tutorial关于机器学习,其中使用了以下代码: import pandas as pd from sklearn.model_selection import train_test
当我尝试使用 StratifiedGroupKFold 时出现 ImportError从 sklearn 中拆分出来。 我注意到使用它需要夜间构建并且我已经安装了它,但我收到错误。欢迎就如何解决此问题
我正在尝试使用 sklearn 库在 LatentDirichletAllocation 上应用 GridSearchCV。 当前流水线如下所示: vectorizer = CountVectoriz
我正在尝试使用 sklearn 库在 LatentDirichletAllocation 上应用 GridSearchCV。 当前流水线如下所示: vectorizer = CountVectoriz
我正在尝试使用 sklearn.model_selection 中的 GridSearhCV 进行参数调整 我不知何故不断收到 ValueError: C in () 1 gs = Gr
我最近开始使用 sklearn 并偶然发现了 Stratified ShuffleSplit 函数。尽管我理解它的概念和它的用途,但我不太理解它运行所需的参数,例如n_split。根据sklearn的
我正在使用 svm 对新闻组主题进行分类。我正在提供最好的解决方案来对这些数据进行分类。请帮助删除这个错误,它阻止了我的整个项目。在这里,当我通过 GridSearchCV 库调用拟合方法时,它显示了
我正在尝试使用 GridSearchCV 实现决策树分类器。实现后,我尝试访问 cv_results_.mean_train_score 但出现关键错误。 tuned_parameters =
我是一名优秀的程序员,十分优秀!