【问题标题】:matlab equivalent of python sklearn train_test_split function?matlab相当于python sklearn train_test_split函数?
【发布时间】:2015-04-08 15:55:53
【问题描述】:

如何在 matlab 中获取相当于 python 的代码

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

应该对训练和测试数据集进行随机抽样,因为我将多次重复此过程以执行引导。

【问题讨论】:

    标签: python matlab scikit-learn cross-validation


    【解决方案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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-04
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多