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.
After applying the NB model on certain data I was trying to get the top 20 probabilities.
argsort()
function return the indices of values from low probability to high probability so I have inverted the data.
Now I want to know the indices of top 20 value. How can I get it?
要获取排序列表的前n
值,请使用:
top_n = feature_log_prob_sorted[:n]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.