繁体   English   中英

sklearn的precision_score函数输入错误

[英]Type error with sklearn's accuracy_score function

我正在尝试在python中从sklearn.metrics运行precision_score。 我的真实y和预测y均为稀疏矩阵格式-

import scipy.sparse as sp
from sklearn.metrics import accuracy_score
y_true = sp.csr_matrix(y.values) # where y is a multi-label dataframe
y_pred = model.predict(X) # X is same format as y_true    
accuracy_score(y_true, y_pred)

我收到以下错误:

TypeError: len() of unsized object

我检查了文档 ,它应该能够接受稀疏矩阵。

为了清楚起见,当我尝试查看其内容时,会同时获得以下内容:

[In]  y_true
[Out] <9646x1248 sparse matrix of type '<class 'numpy.int64'>'
                 with 36700 stored elements in Compressed Sparse Row format>
[In]  y_pred
[Out] <9646x1248 sparse matrix of type '<class 'numpy.int64'>'
                 with 373603 stored elements in Compressed Sparse Row format>

为什么会出现此错误,以及如何解决输入问题?

将矩阵转换为规则矩阵y_pred = y_pred.Ay_true = y_true.A ,然后计算accuracy_score(y_true, y_pred)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM