遇到AttributeError: ‘numpy.ndarray‘ object has no attribute ‘value_counts‘没有Value——counts属性

在使用Numpy时候,AttributeError: ‘numpy.ndarray’ object has no attribute ‘value_counts’,表示numpy.ndarray没有value_counts属性的解决办法

Traceback (most recent call last):
  File "C:/Users/kingS/PycharmProjects/python学习/机器学习/比赛_西财/test11.py", line 58, in <module>
    print(y_predict.value_counts())
AttributeError: 'numpy.ndarray' object has no attribute 'value_counts'

我们需要将统计频率的变量转为series类型

print('判定结果:%s'%y_predict)
# y_predict=pd.Series(y_predict)
print(y_predict.value_counts())

转换如下

y_predict=pd.Series(y_predict)

结果:

0    4568
1      16
dtype: int64

你可能感兴趣的:(python基础,python,机器学习,numpy,数据分析)