split - 方法 "stratify"中的参数 "train_test_split"(scikit Learn)

标签 split scikit-learn training-data test-data

我正在尝试使用 scikit Learn 包中的 train_test_split,但我在使用参数 stratify 时遇到问题。以下是代码:

from sklearn import cross_validation, datasets 

X = iris.data[:,:2]
y = iris.target

cross_validation.train_test_split(X,y,stratify=y)

但是,我不断遇到以下问题:

raise TypeError("Invalid parameters passed: %s" % str(options))
TypeError: Invalid parameters passed: {'stratify': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])}

有人知道发生了什么事吗?下面是函数文档。

[...]

stratify : array-like or None (default is None)

If not None, data is split in a stratified fashion, using this as the labels array.

New in version 0.17: stratify splitting

[...]

最佳答案

stratify参数进行分割,以便生成的样本中的值的比例与提供给参数stratify的值的比例相同。

例如,如果变量 y 是值为 01 的二元分类变量,并且有 25% 的零和 75%其中,stratify=y 将确保您的随机分割包含 25% 的 0 和 75% 的 1

关于split - 方法 "stratify"中的参数 "train_test_split"(scikit Learn),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34842405/

相关文章:

c++ - 使用 C++ 正则表达式查找第一个匹配项的索引

Java String split 删除了空值

c++ - 在 C++ 中使用 boost 拆分字符串两次?

python - 具有大数据集的 DictVectorizer

python - 计算宏观/微观平均值

python - 从文件到列表中元组的字符串

machine-learning - 在scikit-learn中,DBSCAN可以使用稀疏矩阵吗?

Python 训练和测试错误

python - child 数据库的 Dlib 培训

java - 创建我们自己的模型来训练 openNLP 并在 java 中使用它