Python之 sklearn:sklearn中的train_test_split函数的简介及使用方法之详细攻略
目录
sklearn中的train_test_split函数的简介
sklearn.model_selection.train_test_split(*arrays, **options)[source] Split arrays or matrices into random train and test subsets Quick utility that wraps input validation and next(ShuffleSplit().split(X, y)) and application to input data into a single call for splitting (and optionally subsampling) data in a oneliner. | sklearn.model_selection.train_test_split(*数组,* *选项)[源] |
Parameters test_size:float or int, default=None train_size:float or int, default=None random_state:int or RandomState instance, default=None shuffle:bool, default=True stratify:array-like, default=None | 参数 test_size:float或int,默认=无 train_size:float或int,默认为无 random_state:int或RandomState实例,默认为None shuffle:bool,默认= True stratify:array-like默认=没有 |
Returns New in version 0.16: If the input is sparse, the output will be a scipy.sparse.csr_matrix. Else, output type is the same as the input type. | 返回 版本0.16中的新内容:如果输入是稀疏的,则输出将是scipy.sparse.csr_matrix.。否则,输出类型与输入类型相同。 |
- -meta">>>> import numpy as np
- -meta">>>> from sklearn.model_selection import train_test_split
- -meta">>>> X, y = np.arange(10).reshape((5, 2)), range(5)
- -meta">>>> X
- array([[0, 1],
- [2, 3],
- [4, 5],
- [6, 7],
- [8, 9]])
- -meta">>>> list(y)
- [0, 1, 2, 3, 4]
- >>>
- -meta">>>> X_train, X_test, y_train, y_test = train_test_split(
- -meta">... X, y, test_size=0.33, random_state=42)
- ...
- -meta">>>> X_train
- array([[4, 5],
- [0, 1],
- [6, 7]])
- -meta">>>> y_train
- [2, 0, 3]
- -meta">>>> X_test
- array([[2, 3],
- [8, 9]])
- -meta">>>> y_test
- [1, 4]
- >>>
- -meta">>>> train_test_split(y, shuffle=False)
- [[0, 1, 2], [3, 4]]
网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。
加入交流群
请使用微信扫一扫!