model_selection.
from sklearn.model_selection import
用于数据集划分
评估评估
train_test_split
总结:
做数据集划分,也可以这样用:
- 不把
y
做映射也可以划分 y
是多label也可以划分- 初步判断是一个组合作为一类,然后按比例划分,因此指定
stratify
后,也是按层次划分的
- 初步判断是一个组合作为一类,然后按比例划分,因此指定
demo
from sklearn.model_selection import train_test_split
X = [['0', '1', '2'], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10],
[1, 2, 3]]
y = [[0, 0, ], [1, 1, ], [0, 1, ], [1, 1, ], [0, 0, ], [1, 2, ], [0, 1, ], [1, 2, ], [0, 2, ], [0, 2]]
y = [['a', '0', ], ['1', '1', ], ['a', '1', ], ['1', '1', ], ['a', '0', ], ['1', '2', ], ['a', '1', ], ['1', '2', ],
['a', '2', ], ['a', '2']]
train_X, test_X, train_y, test_y = train_test_split(X, y, stratify=y, train_size=0.5, random_state=1, shuffle=True)
print(train_X)
print(train_y)
print(test_X)
print(test_y)