我如何在matlab中获得python代码的等效代码
x_train, x_test, y_train, y_test = sk.cross_validation.train_test_split(X,y)
训练和测试数据集应该是随机采样的,因为我会多次重复这个过程来执行引导。
假设您有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))