def mutual_info_rank_features(feature_vecs, binary_labels):
"""
Given a set of feature vectors and binary labels, return
the list of indices of the features ranked by mutual information
with the binary labels.
Args:
feature_vecs: list of feature vectors
binary_labels: list of binary labels
"""
# Convert Features to Boolean values
bin_feature_vecs = []
for feature_v in feature_vecs:
nfv = []
for elem in feature_v:
if elem > 0:
nfv.append(1)
else:
nfv.append(0)
bin_feature_vecs.append(nfv)
mutual_infos = []
num_features = len(bin_feature_vecs[0])
for i in range(num_features):
row_i = [x[i] for x in bin_feature_vecs]
mi = mutual_info_score(row_i, binary_labels)
mutual_infos.append(mi)
ranked_indices = [index for (mi,index) in sorted(zip(mutual_infos,[x for x in range(num_features)]))]
return ranked_indices
one_vs_rest_classifier_same_features.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录