Python之 sklearn:sklearn中的train_test_split函数的简介及使用方法之详细攻略
Python之 sklearn:sklearn中的train_test_split函數的簡介及使用方法之詳細攻略
?
?
?
目錄
sklearn中的train_test_split函數的簡介
train_test_split使用方法
1、基礎用法
?
?
?
sklearn中的train_test_split函數的簡介
官方文檔:https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html?highlight=train_test_split#sklearn.model_selection.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.。否則,輸出類型與輸入類型相同。 |
?
train_test_split使用方法
1、基礎用法
>>> import numpy as np >>> from sklearn.model_selection import train_test_split >>> X, y = np.arange(10).reshape((5, 2)), range(5) >>> X array([[0, 1],[2, 3],[4, 5],[6, 7],[8, 9]]) >>> list(y) [0, 1, 2, 3, 4] >>> >>> X_train, X_test, y_train, y_test = train_test_split( ... X, y, test_size=0.33, random_state=42) ... >>> X_train array([[4, 5],[0, 1],[6, 7]]) >>> y_train [2, 0, 3] >>> X_test array([[2, 3],[8, 9]]) >>> y_test [1, 4] >>> >>> train_test_split(y, shuffle=False) [[0, 1, 2], [3, 4]]?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的Python之 sklearn:sklearn中的train_test_split函数的简介及使用方法之详细攻略的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成功解决Eclipse打开py等文件出现
- 下一篇: 成功解决ValueError: With