简体   繁体   English

如何获取特定行集的索引

[英]how to get the indices of specific set of rows

feature_log_prob_sorted = np.abs(naive.feature_log_prob_).argsort()

feature_log_prob_sorted = feature_log_prob_sorted[ : : -1]

Here naive is BernoulliNB's object and feature_log_prob_ is empirical log probability of features given a class.这里 naive 是 BernoulliNB 的对象, feature_log_prob_是给定类的特征的经验对数概率。

After applying the NB model on certain data I was trying to get the top 20 probabilities.在某些数据上应用 NB 模型后,我试图获得前 20 个概率。

argsort() function return the indices of values from low probability to high probability so I have inverted the data. argsort()函数返回从低概率到高概率的值的索引,所以我已经反转了数据。

Now I want to know the indices of top 20 value.现在我想知道前 20 个值的指数。 How can I get it?我怎么才能得到它?

要获取排序列表的前n值,请使用:

top_n = feature_log_prob_sorted[:n]

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

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