划分训练集,验证集和测试集(keras)

划分80%的训练集,10%的验证集,10%的测试集
使用skleran的train_test_split进行划分,分两次进行。

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.20, random_state = 0)
x_test, x_valid, y_test, y_valid = train_test_split(x_test, y_test, test_size = 0.5, random_state = 0)

#查看是否按比例正确划分数据集
print(len(x_train),len(x_valid),len(x_test)) #输出训练集,验证集大小

你可能感兴趣的:(python,机器学习)