参数“分层"为"0".来自方法"train_test_split" (scikit学习) [英] Parameter "stratify" from method "train_test_split" (scikit Learn)

查看:132
本文介绍了参数“分层"为"0".来自方法"train_test_split" (scikit学习)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用scikit Learn软件包中的train_test_split,但是我在使用参数stratify时遇到了麻烦.以下是代码:

I am trying to use train_test_split from package scikit Learn, but I am having trouble with parameter stratify. Hereafter is the code:

from sklearn import cross_validation, datasets 

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

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

但是,我仍然遇到以下问题:

However, I keep getting the following problem:

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])}

有人知道发生了什么吗?下面是功能文档.

Does someone have an idea what is going on? Below is the function documentation.

[...]

[...]

分层:类似数组或无(默认为无)

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

如果不设置为None,则将数据作为标签数组以分层方式进行拆分.

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

0.17版中的新功能:分层拆分

[...]

推荐答案

Scikit-Learn只是告诉您它无法识别参数"stratify",而不是您使用了错误的参数.这是因为该参数是在您引用的文档中指出的版本0.17中添加的.

Scikit-Learn is just telling you it doesn't recognise the argument "stratify", not that you're using it incorrectly. This is because the parameter was added in version 0.17 as indicated in the documentation you quoted.

因此,您只需要更新Scikit-Learn.

So you just need to update Scikit-Learn.

这篇关于参数“分层"为"0".来自方法"train_test_split" (scikit学习)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆