Scikit-learn train_test_split with indices

后端 未结 5 947
忘了有多久
忘了有多久 2020-12-04 14:07

How do I get the original indices of the data when using train_test_split()?

What I have is the following

from sklearn.cross_validation import train_         


        
5条回答
  •  清歌不尽
    2020-12-04 14:36

    If you are using pandas you can access the index by calling .index of whatever array you wish to mimic. The train_test_split carries over the pandas indices to the new dataframes.

    In your code you simply use x1.index and the returned array is the indexes relating to the original positions in x.

提交回复
热议问题