标签:return val 切分 shu its test core names rand
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.4, random_state=0)
from sklearn.model_selection import ShuffleSplit
sample = pd.DataFrame()
rs = ShuffleSplit(n_splits=5, test_size=0.2, random_state=0)
for train_indices, test_indices in rs.split(sample):
#共循环5次
#每次循环拿到打乱顺序的训练集和验证集的索引值,训练集数量为80%,测试集数量为20%
这种数据切分方式经常与CV结合使用
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import ShuffleSplit
cv = ShuffleSplit(n_splits=3, test_size=0.3, random_state=0)
cross_val_score(clf, iris.data, iris.target, cv=cv)
from sklearn.model_selection import GroupShuffleSplit
sample = pd.DataFrame()
rs = GroupShuffleSplit(n_splits=4, test_size=0.25, random_state=0)
#获取组标记
_, driver_indices = np.unique(np.array(driver_ids), return_inverse=True)
driver_indices = [0 0 1 1 1 2 2 2 2 3]
#这里是按照groups所给列的类别进行数据集的划分
for train_indices, test_indices in rs.split(x_train_names_all, y_train_labels_all, groups=driver_indices):
#共循环4次
#假设groups列中有4个类别,每次循环,从中选择75%的类别数,属于这75%的类别数的所有数据集作为训练集,其余
#为验证集。
标签:return val 切分 shu its test core names rand
原文地址:https://www.cnblogs.com/yongfuxue/p/10095389.html