在 scikit 中使用训练测试拆分时获取索引 [英] Getting indices while using train test split in scikit

查看:47
本文介绍了在 scikit 中使用训练测试拆分时获取索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了将我的数据分别拆分为训练数据和测试数据,我使用了

In order to split my data into train and test data separately, I'm using

sklearn.cross_validation.train_test_split 函数.

当我将我的数据和标签作为列表列表提供给此函数时,它会在两个单独的列表中返回训练和测试数据.

When I supply my data and labels as list of lists to this function, it returns train and test data in two separate lists.

我想从原始数据列表中获取训练和测试数据元素的索引.

I want to get the indices of the train and test data elements from the original data list.

谁能帮我解决这个问题?

Can anyone help me out with this?

提前致谢

推荐答案

您可以提供索引向量作为附加参数.使用 sklearn 中的示例:

You can supply the index vector as an additional argument. Using the example from sklearn:

import numpy as np
from sklearn.cross_validation import train_test_split
X, y,indices = (0.1*np.arange(10)).reshape((5, 2)),range(10,15),range(5)
X_train, X_test, y_train, y_test,indices_train,indices_test = train_test_split(X, y,indices, test_size=0.33, random_state=42)
indices_train,indices_test
#([2, 0, 3], [1, 4])

这篇关于在 scikit 中使用训练测试拆分时获取索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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