sklearn.model_selection.train_test_split随机划分训练集和测试集
官网文档:http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html#sklearn.model_selection.train_test_split
- 一般形式:
train_test_split是交叉验证中常用的函数,功能是从样本中随机的按比例选取train data和testdata,形式为:
X_train,X_test, y_train, y_test =
cross_validation.train_test_split(train_data,train_target,test_size=0.4, random_state=0)
- 参数解释:
train_data:所要划分的样本特征集
train_target:所要划分的样本结果
test_size:样本占比,如果是整数的话就是样本的数量
random_state:是随机数的种子。
随机数种子:其实就是该组随机数的

本文介绍如何使用sklearn的train_test_split函数随机划分训练集和测试集,并通过示例展示其用法。该函数可帮助实现样本的随机拆分,避免过拟合,适用于交叉验证场景。

640

被折叠的 条评论
为什么被折叠?



