ValueError: Cannot Have Number Of Splits N_splits=3 Greater Than The Number Of Samples: 1
I am trying this training modeling using train_test_split and a decision tree regressor: import sklearn from sklearn.model_selection import train_test_split from sklearn.tree impor
Solution 1:
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.
Post a Comment for "ValueError: Cannot Have Number Of Splits N_splits=3 Greater Than The Number Of Samples: 1"