import numpy
# x is your dataset
x = numpy.random.rand(100, 5)
numpy.random.shuffle(x)
training, test = x[:80,:], x[80:,:]
或者
import numpy
# x is your dataset
x = numpy.random.rand(100, 5)
indices = numpy.random.permutation(x.shape[0])
training_idx, test_idx = indices[:80], indices[80:]
training, test = x[training_idx,:], x[test_idx,:]
import numpy
# x is your dataset
x = numpy.random.rand(100, 5)
training_idx = numpy.random.randint(x.shape[0], size=80)
test_idx = numpy.random.randint(x.shape[0], size=20)
training, test = x[training_idx,:], x[test_idx,:]
只是个便条。如果需要训练、测试和验证集,可以执行以下操作:
这些参数将提供70%的训练,15%的测试和val集。希望这有帮助。
还有一个选择,就是使用scikit learn。作为scikit's wiki describes,您只需使用以下说明:
这样,你就可以保持同步的标签为数据,你正试图分裂成训练和测试。
如果要将数据集一分为二,则可以使用
numpy.random.shuffle
;如果需要跟踪索引,则可以使用numpy.random.permutation
:或者
有很多方法可以repeatedly partition the same data set for cross validation。一种策略是从数据集中重新采样,重复:
最后,sklearn包含several cross validation methods(k-fold,leave-n-out,…)。它还包括更高级的"stratified sampling"方法,这些方法创建的数据分区相对于某些特性是平衡的,例如,确保在训练和测试集中有相同比例的正示例和负示例。
相关问题 更多 >
编程相关推荐