是否
class sklearn.cross_validation.ShuffleSplit( n, n_iterations=10, test_fraction=0.10000000000000001, indices=True, random_state=None)
是scikit-learn中进行10*10折交叉验证的正确方法?(通过将random_state
设置为10个不同的数字来实现)
因为我在Stratified K-Fold
或K-Fold
中没有找到random_state
参数,并且K-Fold
对于相同数据的分割总是相同的。
如果ShuffleSplit
是正确的,那么一个担忧是它提到
注意:与其他交叉验证策略不同,随机分割不能保证所有折叠都是不同的,尽管对于大型数据集来说,这种情况仍然非常可能
对于10*10折交叉验证,这总是如此吗?
回答:
我不确定你所说的10*10交叉验证是什么意思。你提供的ShuffleSplit配置将使你调用估算器的fit方法10次。如果你通过显式使用外部循环调用它10次,或者如果直接在一个循环中使用100次,并保留10%的数据用于测试,你可以使用以下方式:
>>> ss = ShuffleSplit(X.shape[0], n_iterations=100, test_fraction=0.1,... random_state=42)
如果你想进行10次StratifiedKFold,每次k=10,你可以在每次运行之间对数据集进行洗牌(这将导致总共100次对fit方法的调用,每次调用fit时使用90%的训练数据和10%的测试数据):
>>> from sklearn.utils import shuffle>>> from sklearn.cross_validation import StratifiedKFold, cross_val_score>>> for i in range(10):... X, y = shuffle(X_orig, y_orig, random_state=i)... skf = StratifiedKFold(y, 10)... print cross_val_score(clf, X, y, cv=skf)