如何在链接中显示此给定模型的准确性,准确性,召回率,f1量度?

时间:2019-12-13 19:09:18

标签: python machine-learning data-science recommendation-engine

首先,对于如此直接的问题,我深感抱歉。 我看过这篇文章:link最近。现在我正在做作业。我试图显示模型的准确性,准确性,召回率,f1度量。但是这样做没有成功。 我的问题可以显示所提出模型的准确性,准确性,召回率,f1度量吗?

```from sklearn.metrics import precision_recall_fscore_support as score

precision, recall, fscore, support = score(trainset, predictions)

print('precision: {}'.format(precision))
print('recall: {}'.format(recall))
print('fscore: {}'.format(fscore))
print('support: {}'.format(support))```



 ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-38-70db6200efad> in <module>
      1 from sklearn.metrics import precision_recall_fscore_support as score
      2 
----> 3 precision, recall, fscore, support = score(trainset, predictions)
      4 
      5 print('precision: {}'.format(precision))

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\classification.py in precision_recall_fscore_support(y_true, y_pred, beta, labels, pos_label, average, warn_for, sample_weight)
   1413         raise ValueError("beta should be >0 in the F-beta score")
   1414     labels = _check_set_wise_labels(y_true, y_pred, average, labels,
-> 1415                                     pos_label)
   1416 
   1417     # Calculate tp_sum, pred_sum, true_sum ###

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\classification.py in _check_set_wise_labels(y_true, y_pred, average, labels, pos_label)
   1237                          str(average_options))
   1238 
-> 1239     y_type, y_true, y_pred = _check_targets(y_true, y_pred)
   1240     present_labels = unique_labels(y_true, y_pred)
   1241     if average == 'binary':

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\classification.py in _check_targets(y_true, y_pred)
     69     y_pred : array or indicator matrix
     70     """
---> 71     check_consistent_length(y_true, y_pred)
     72     type_true = type_of_target(y_true)
     73     type_pred = type_of_target(y_pred)

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_consistent_length(*arrays)
    199     """
    200 
--> 201     lengths = [_num_samples(X) for X in arrays if X is not None]
    202     uniques = np.unique(lengths)
    203     if len(uniques) > 1:

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in <listcomp>(.0)
    199     """
    200 
--> 201     lengths = [_num_samples(X) for X in arrays if X is not None]
    202     uniques = np.unique(lengths)
    203     if len(uniques) > 1:

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in _num_samples(x)
    140         else:
    141             raise TypeError("Expected sequence or array-like, got %s" %
--> 142                             type(x))
    143     if hasattr(x, 'shape'):
    144         if len(x.shape) == 0:

TypeError: Expected sequence or array-like, got <class 'surprise.trainset.Trainset'>

0 个答案:

没有答案