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

查看:37
本文介绍了参数“分层"来自方法“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 : 类数组或无(默认为无)

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 只是告诉您它无法识别参数分层",而不是您使用不当.这是因为该参数是在您引用的文档中指出的 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.

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

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