ValueError: Cannot have number of splits n_splits=3 greater than the number of samples: 1

喜你入骨 提交于 2019-12-02 08:00:35
qmaruf

If the number of splits is greater than number of samples, you will get the first error. Check the snippet from the source code given below:

if self.n_splits > n_samples:
    raise ValueError(
        ("Cannot have number of splits n_splits={0} greater"
         " than the number of samples: {1}.").format(self.n_splits,
                                                     n_samples))

If the number of folds is less than or equal 1, you will get the second error. In your case, the cv = 1. Check the source code:

if n_folds <= 1:
            raise ValueError(
                "k-fold cross validation requires at least one"
                " train / test split by setting n_folds=2 or more,"
                " got n_folds={0}.".format(n_folds))

An educated guess, the number of samples in X_test is less than 3. Check that carefully.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!