本文简要介绍python语言中 sklearn.model_selection.LeaveOneGroupOut
的用法。
用法:
class sklearn.model_selection.LeaveOneGroupOut
留下一组cross-validator
提供训练/测试索引以根据第三方提供的组拆分数据。该组信息可用于将样本的任意域特定分层编码为整数。
例如,这些组可以是样本收集的年份,因此允许针对基于时间的拆分进行交叉验证。
在用户指南中阅读更多信息。
例子:
>>> import numpy as np >>> from sklearn.model_selection import LeaveOneGroupOut >>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]]) >>> y = np.array([1, 2, 1, 2]) >>> groups = np.array([1, 1, 2, 2]) >>> logo = LeaveOneGroupOut() >>> logo.get_n_splits(X, y, groups) 2 >>> logo.get_n_splits(groups=groups) # 'groups' is always required 2 >>> print(logo) LeaveOneGroupOut() >>> for train_index, test_index in logo.split(X, y, groups): ... 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] ... print(X_train, X_test, y_train, y_test) TRAIN: [2 3] TEST: [0 1] [[5 6] [7 8]] [[1 2] [3 4]] [1 2] [1 2] TRAIN: [0 1] TEST: [2 3] [[1 2] [3 4]] [[5 6] [7 8]] [1 2] [1 2]
相关用法
- Python sklearn LeaveOneOut用法及代码示例
- Python sklearn LeavePOut用法及代码示例
- Python sklearn LeavePGroupsOut用法及代码示例
- 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.LeaveOneGroupOut。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。