How to split/partition a dataset into training and test datasets for, e.g., cross validation?

前端 未结 12 2005
醉话见心
醉话见心 2020-11-27 10:42

What is a good way to split a NumPy array randomly into training and testing/validation dataset? Something similar to the cvpartition or crossvalind

12条回答
  •  渐次进展
    2020-11-27 11:36

    As sklearn.cross_validation module was deprecated, you can use:

    import numpy as np
    from sklearn.model_selection import train_test_split
    X, y = np.arange(10).reshape((5, 2)), range(5)
    
    X_trn, X_tst, y_trn, y_tst = train_test_split(X, y, test_size=0.2, random_state=42)
    

提交回复
热议问题