matlab相当于python sklearn train_test_split函数?

时间:2015-04-08 15:55:54

标签: python matlab scikit-learn cross-validation

如何在matlab中获得与python代码相同的内容

x_train, x_test, y_train, y_test = sk.cross_validation.train_test_split(X,y)

列车和测试数据集应该是随机抽样的,因为我会多次重复这个过程来执行bootstrap。

1 个答案:

答案 0 :(得分:1)

假设您有150个样本要分成100个样本进行培训,50个样本进行测试。你可以这么做:

的Python:

import numpy as np

idx = np.random.permutation(range(len(y)))
X_train, y_train = X[idx[:100]], y[idx[:100]]
X_test, y_test = X[idx[100:]], y[idx[100:]]

MATLAB /八度:

idx = randperm(length(y))
X_train, y_train = X(idx(1:100)), y(idx(1:100))
X_test, y_test = X(idx(100:150)), y(idx(100:150))