问答详情
源自:2-4 模型评估:准确率、数据分离、参数选择(2)

老师您好,这个是怎么回事呢


---------------------------------------------------------------------------ValueError                                Traceback (most recent call last)<ipython-input-12-b521df40db00> in <module>      1 #分离后模型预测的准确率----> 2 print(accuracy_score(y_train,y_test_pred))D:\Anaconda\lib\site-packages\sklearn\metrics\_classification.py in accuracy_score(y_true, y_pred, normalize, sample_weight)    183     184     # Compute accuracy for each possible representation--> 185     y_type, y_true, y_pred = _check_targets(y_true, y_pred)    186     check_consistent_length(y_true, y_pred, sample_weight)    187     if y_type.startswith('multilabel'):D:\Anaconda\lib\site-packages\sklearn\metrics\_classification.py in _check_targets(y_true, y_pred)     78     y_pred : array or indicator matrix     79     """---> 80     check_consistent_length(y_true, y_pred)     81     type_true = type_of_target(y_true)     82     type_pred = type_of_target(y_pred)D:\Anaconda\lib\site-packages\sklearn\utils\validation.py in check_consistent_length(*arrays)    210     if len(uniques) > 1:    211         raise ValueError("Found input variables with inconsistent numbers of"--> 212                          " samples: %r" % [int(l) for l in lengths])    213     214 ValueError: Found input variables with inconsistent numbers of samples: [90, 60]


提问者:慕沐1300483 2020-04-15 18:40

个回答

  • ___Cc
    2020-07-17 20:51:11

    accuracy_score(y_train,y_test_pred)

    这样你在比对的时候,y_train是取的训练集中的label,y_test_pred是预测的测试集的label,两个维度不同当然不能比对

  • 面包与理想
    2020-04-20 16:56:46

    Found input variables with inconsistent numbers of samples: [90, 60]

    检查样本维度。