用途
在机器学习中,该函数可按照用户设定的比例,随机将样本集合划分为训练集 和测试集,并返回划分好的训练集和测试集数据。
语法
X_train,X_test, y_train, y_test =cross_validation.train_test_split(X,y,test_size, random_state)
参数说明
Code | Text |
---|---|
X | 待划分的样本特征集合 |
y | 待划分的样本标签 |
test_size | 若在0~1之间,为测试集样本数目与原始样本数目之比;若为整数,则是测试集样本的数目。 |
random_state | 随机数种子 |
X_train | 划分出的训练集数据(返回值) |
X_test | 划分出的测试集数据(返回值) |
y_train | 划分出的训练集标签(返回值) |
y_test | 划分出的测试集标签(返回值) |
代码示例
输入: