人工智能 LeaveOneOut(留一法)(LOO)
1、代码n:数据集大小from sklearn.model_selection import LeaveOneOutX=np.array([[1,2,3,4],[11,12,13,14],[21,22,23,24],[31,32,33,34]])y=np.array([1,1,0,0])lo=LeaveOneOut()# lo.len(y)for train_index,test_index in
1、代码
n:数据集大小
from sklearn.model_selection import LeaveOneOut
X=np.array([[1,2,3,4],
[11,12,13,14],
[21,22,23,24],
[31,32,33,34]])
y=np.array([1,1,0,0])
lo=LeaveOneOut()
# lo.len(y)
for train_index,test_index in lo.split(X):
print("Train Index:",train_index)
print("Test Index:",test_index)
print("X_train:",X[train_index])
print("X_test:",X[test_index])
print("")
2、结果
【out】:
Train Index: [1 2 3]
Test Index: [0]
X_train: [[11 12 13 14]
[21 22 23 24]
[31 32 33 34]]
X_test: [[1 2 3 4]]Train Index: [0 2 3]
Test Index: [1]
X_train: [[ 1 2 3 4]
[21 22 23 24]
[31 32 33 34]]
X_test: [[11 12 13 14]]Train Index: [0 1 3]
Test Index: [2]
X_train: [[ 1 2 3 4]
[11 12 13 14]
[31 32 33 34]]
X_test: [[21 22 23 24]]Train Index: [0 1 2]
Test Index: [3]
X_train: [[ 1 2 3 4]
[11 12 13 14]
[21 22 23 24]]
X_test: [[31 32 33 34]]

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)