本文簡要介紹python語言中 sklearn.model_selection.LeavePOut
的用法。
用法:
class sklearn.model_selection.LeavePOut(p)
Leave-P-Out cross-validator
提供訓練/測試索引以拆分訓練/測試集中的數據。這導致對大小為 p 的所有不同樣本進行測試,而剩餘的 n - p 個樣本在每次迭代中形成訓練集。
注意:
LeavePOut(p)
不等同於創建非重疊測試集的KFold(n_splits=n_samples // p)
。由於隨著樣本數量的增加而增加的迭代次數較多,這種交叉驗證方法的成本可能非常高。對於大型數據集,應該支持
KFold
、StratifiedKFold
或ShuffleSplit
。在用戶指南中閱讀更多信息。
- p:int
測試集的大小。必須嚴格小於樣本數。
參數:
例子:
>>> import numpy as np >>> from sklearn.model_selection import LeavePOut >>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]]) >>> y = np.array([1, 2, 3, 4]) >>> lpo = LeavePOut(2) >>> lpo.get_n_splits(X) 6 >>> print(lpo) LeavePOut(p=2) >>> for train_index, test_index in lpo.split(X): ... print("TRAIN:", train_index, "TEST:", test_index) ... X_train, X_test = X[train_index], X[test_index] ... y_train, y_test = y[train_index], y[test_index] TRAIN: [2 3] TEST: [0 1] TRAIN: [1 3] TEST: [0 2] TRAIN: [1 2] TEST: [0 3] TRAIN: [0 3] TEST: [1 2] TRAIN: [0 2] TEST: [1 3] TRAIN: [0 1] TEST: [2 3]
相關用法
- Python sklearn LeavePGroupsOut用法及代碼示例
- Python sklearn LeaveOneOut用法及代碼示例
- Python sklearn LeaveOneGroupOut用法及代碼示例
- Python sklearn LedoitWolf用法及代碼示例
- Python sklearn LarsCV用法及代碼示例
- Python sklearn Lars用法及代碼示例
- Python sklearn LocalOutlierFactor.kneighbors_graph用法及代碼示例
- Python sklearn Lasso用法及代碼示例
- Python sklearn LabelPropagation用法及代碼示例
- Python sklearn LassoLars用法及代碼示例
- Python sklearn LogisticRegression用法及代碼示例
- Python sklearn LassoLarsIC用法及代碼示例
- Python sklearn LocallyLinearEmbedding用法及代碼示例
- Python sklearn LassoCV.path用法及代碼示例
- Python sklearn LogisticRegressionCV用法及代碼示例
- Python sklearn LinearDiscriminantAnalysis用法及代碼示例
- Python sklearn LassoCV用法及代碼示例
- Python sklearn LabelSpreading用法及代碼示例
- Python sklearn LabelEncoder用法及代碼示例
- Python sklearn LinearRegression用法及代碼示例
- Python sklearn LocalOutlierFactor.kneighbors用法及代碼示例
- Python sklearn LabelBinarizer用法及代碼示例
- Python sklearn LinearSVR用法及代碼示例
- Python sklearn LinearSVC用法及代碼示例
- Python sklearn LassoLarsCV用法及代碼示例
注:本文由純淨天空篩選整理自scikit-learn.org大神的英文原創作品 sklearn.model_selection.LeavePOut。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。