【问题标题】:Cross validation with specific test size具有特定测试规模的交叉验证
【发布时间】:2016-02-09 21:56:00
【问题描述】:

我之前使用 cross_validation.train_test_split 将我的数据集拆分为 90:10 的比例。我现在转到了 Stratified Shuffle Split(在 scikit-learn 中合并了 Kfold 和 Shuffle Split)。我想了解使用指定的测试大小进行分层划分是否更好,还是我应该不指定测试大小就这样做?

这就是我正在做的:

train=[]
with open("/Users/minks/Documents/documents.txt") as f:
    for line in f:
        train.append(line.strip().split())
train=np.array(train)
labels=[]
with open("/Users/minks/Documents/Labels.txt") as t:
    for line in t:
        labels.extend(line.strip().split())
labels=np.array(labels)

kf=StratifiedShuffleSplit(labels, n_iter=5, test_size=0.10)

for train_index, test_index in kf:
     X_train, X_test = train[train_index],train[test_index]
     Y_train, Y_test = labels[train_index],labels[test_index]

我想知道指定 test_size 是否是一个好的性能决定,因为如果我不这样做,它会获取随机比率。

【问题讨论】:

    标签: python scikit-learn


    【解决方案1】:

    如果您不指定自己的测试大小,则默认为0.1。它不会使用随机比率。您可以在文档中找到默认值(函数的字符串):

    在 IPython 中,做

    [1]: from sklearn.cross_validation import StratifiedShuffleSplit
    [2]: StratifiedShuffleSplit?
    

    你会看到

    [...]
    Parameters
    ----------
    n : int
        Total number of elements in the dataset.
    
    n_iter : int (default 10)
        Number of re-shuffling & splitting iterations.
    
    test_size : float (default 0.1), int, or None
        If float, should be between 0.0 and 1.0 and represent the
        proportion of the dataset to include in the test split. If
        int, represents the absolute number of test samples. If None,
        the value is automatically set to the complement of the train size.
    
    [...]
    

    【讨论】:

      猜你喜欢
      • 2019-07-30
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      • 2020-09-22
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2019-12-10
      相关资源
      最近更新 更多