请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

ValueError: Found input variables

%%time
from sklearn.model_selection import GridSearchCV
grid_search = GridSearchCV(knn_clf, param_grid)
grid_search.fit(X_train, y_train)
ValueError                                Traceback (most recent call last)
<ipython-input-19-10311b8b707f> in <module>
      1 from sklearn.model_selection import GridSearchCV
      2 grid_search = GridSearchCV(knn_clf, param_grid)
----> 3 grid_search.fit(X_train, y_train)

D:\Software\Anaconda\lib\site-packages\sklearn\model_selection\_search.py in fit(self, X, y, groups, **fit_params)
    628             refit_metric = 'score'
    629 
--> 630         X, y, groups = indexable(X, y, groups)
    631         n_splits = cv.get_n_splits(X, y, groups)
    632 

D:\Software\Anaconda\lib\site-packages\sklearn\utils\validation.py in indexable(*iterables)
    228         else:
    229             result.append(np.array(X))
--> 230     check_consistent_length(*result)
    231     return result
    232 

D:\Software\Anaconda\lib\site-packages\sklearn\utils\validation.py in check_consistent_length(*arrays)
    203     if len(uniques) > 1:
    204         raise ValueError("Found input variables with inconsistent numbers of"
--> 205                          " samples: %r" % [int(l) for l in lengths])
    206 
    207 

ValueError: Found input variables with inconsistent numbers of samples: [1437, 360]

正在回答

1回答

根据你提供的错误信息,X_train 和 y_train 中的样本数量不匹配。使用 shape 看一下这两个变量的维度是不是你要的?


这个课程的所有代码都可以通过慕课网的下载区下载。尝试下载课程的官方代码,在你的环境下运行,看是否有问题?如果没有问题,请仔细调试比对,看看自己的程序问题在哪里?


传送门:https://git.imooc.com/coding-169/coding-169


继续加油!:)

0 回复 有任何疑惑可以回复我~
  • 提问者 慕仰9422463 #1
    找到问题了。是再使用train_test_split函数时,左侧的赋值顺序错误,传入了错误的值。谢谢老师
    回复 有任何疑惑可以回复我~ 2020-02-15 08:51:36
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号