- 使用pd.value_counts
pred_churn = array([0.2, 0.1, 0.1, ..., 0. , 0.2, 0.3])
使用pandas.value_counts即可进行值统计,返回的形式是一个series
counts = pd.value_counts(pred_churn)
0.0 1746 0.1 732 0.2 248 0.3 116 0.7 80 0.6 78 0.8 76 0.9 71 0.4 69 0.5 59 1.0 58 dtype: int64
- 使用Counter
from collections import Counter
c = Counter(pred_churn)
返回一个字典 ,同时可以将字典传入pd.series(c) ,直接变为一个series
Counter({0.2: 248, 0.1: 732, 0.3: 116, 0.4: 69, 0.0: 1746, 0.5: 59, 1.0: 58, 0.6: 78, 0.9: 71, 0.7: 80, 0.8: 76})