1. 描述
Split arrays or matrices into random train and test subsets
2. 语法
train_test_split(*arrays, **options)
3. 参数
1.*arrays:(sequence of indexables with same length / shape[0])
Allowed inputs are lists, numpy arrays, scipy-sparse matrices or pandas dataframes.
2.test_size :(float, int, or None, default None)
If float, should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the train split.
If int, represents the absolute number of train samples.
If None, the value is automatically set to the complement of the test size.
3.random_state :(int, RandomState instance or None, optional (default=None))
If int, random_state is the seed used by the random number generator;
If None, the random number generator is the RandomState instance used by np.ra

本文介绍了如何利用sklearn.model_selection.train_test_split函数将数据集随机划分为训练集和测试集。该函数接受比例或绝对数量作为参数,可以设定随机种子,并支持分层抽样。返回值包括训练集和测试集的分割结果。文中还提供了实例展示如何使用该函数,并展示了划分后的X_train、X_test、y_train和y_test。
最低0.47元/天 解锁文章
792

被折叠的 条评论
为什么被折叠?



