Traceback (most recent call last): File "D:/pythonProject/DATA/jaffeim.ages(1)/test2.py", line 18, in <module> scores = cross_val_score(knn, X, y, cv=5, scoring='accuracy') File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\sklearn\model_selection\_validation.py", line 520, in cross_val_score error_score=error_score, File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\sklearn\model_selection\_validation.py", line 283, in cross_validate for train, test in cv.split(X, y, groups) File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\joblib\parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\joblib\parallel.py", line 833, in dispatch_one_batch islice = list(itertools.islice(iterator, big_batch_size)) File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\sklearn\model_selection\_validation.py", line 268, in <genexpr> delayed(_fit_and_score)( File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\sklearn\model_selection\_split.py", line 340, in split for train, test in super().split(X, y, groups): File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\sklearn\model_selection\_split.py", line 86, in split for test_index in self._iter_test_masks(X, y, groups): File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\sklearn\model_selection\_split.py", line 709, in _iter_test_masks test_folds = self._make_test_folds(X, y) File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\sklearn\model_selection\_split.py", line 673, in _make_test_folds " number of members in each class." % (self.n_splits) ValueError: n_splits=5 cannot be greater than the number of members in each class. 进程已结束,退出代码1
时间: 2023-07-21 13:01:51 浏览: 275
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个错误是由于你在交叉验证过程中设置的分割数(n_splits)大于每个类别中的成员数所引起的。交叉验证中的每个分割都需要保证每个类别都有足够的样本来进行训练和测试,所以分割数不能超过每个类别中的最小样本数。
你可以检查一下你的数据集,看看每个类别中的成员数是否符合要求。如果某个类别的成员数较少,你可以考虑减少分割数或重新调整数据集的样本分布,确保每个类别都有足够的样本进行交叉验证。
阅读全文