gpt4 book ai didi

machine-learning - 如何在 Weka 分类器中按特征的重要性对特征进行排序?

转载 作者:行者123 更新时间:2023-11-30 08:26:12 25 4
gpt4 key购买 nike

我使用 Weka 成功构建了一个分类器。我现在想评估我的功能的有效性或重要性。为此我使用 AttributeSelection。但我不知道如何输出不同的特征及其相应的重要性。我想简单地按信息增益分数的降序列出功能!

最佳答案

对特征进行评分的方法有很多种,在 Weka 中称为属性。这些方法可作为 weka.attributeSelection.ASEvaluation 的子类使用。 .

这些评估类别中的任何一个都会为您提供每个属性的分数。例如,如果您使用信息增益进行评分,您将使用 InfoGainAttributeEval 类。有用的方法是

  • InfoGainAttributeEval.html#buildEvaluator()
  • InfoGainAttributeEval.html#evaluateAttribute()

其他类型的特征评分(增益比、相关性等)具有相同的评分方法。使用其中任何一个,您都可以对所有功能进行排名。

排名本身独立于Weka。在许多方法中,这是一种:

Map<Attribute, Double> infogainscores = new HashMap<Attribute, Double>();
for (int i = 0; i < instances.numAttributes(); i++) {
Attribute t_attr = instaces.attribute(i);
double infogain = evaluation.evaluateAttribute(i);
infogainscores.put(t_attr, infogain);
}

现在您有一个需要按值排序的 map 。这是执行此操作的通用代码:

 /**
* Provides a {@code SortedSet} of {@code Map.Entry} objects. The sorting is in ascending order if {@param order} > 0
* and descending order if {@param order} <= 0.
* @param map The map to be sorted.
* @param order The sorting order (positive means ascending, non-positive means descending).
* @param <K> Keys.
* @param <V> Values need to be {@code Comparable}.
* @return A sorted set of {@code Map.Entry} objects.
*/
static <K,V extends Comparable<? super V>> SortedSet<Map.Entry<K,V>>
entriesSortedByValues(Map<K,V> map, final int order) {
SortedSet<Map.Entry<K,V>> sortedEntries = new TreeSet<>(
new Comparator<Map.Entry<K,V>>() {
public int compare(Map.Entry<K,V> e1, Map.Entry<K,V> e2) {
return (order > 0) ? compareToRetainDuplicates(e1.getValue(), e2.getValue()) : compareToRetainDuplicates(e2.getValue(), e1.getValue());
}
}
);
sortedEntries.addAll(map.entrySet());
return sortedEntries;
}

最后,

private static <V extends Comparable<? super V>> int compareToRetainDuplicates(V v1, V v2) {
return (v1.compareTo(v2) == -1) ? -1 : 1;
}

现在您有一个按值排序的条目列表(按照您的意愿按升序或降序排列)。为之疯狂吧!

请注意,您应该处理多个属性具有相同信息增益的情况。这就是为什么我在保留重复项的同时完成了按值排序的过程。

关于machine-learning - 如何在 Weka 分类器中按特征的重要性对特征进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21267988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com