3

我正在使用 AdaBoost 实现一个应用程序来分类大象是亚洲大象还是非洲大象。我的输入数据是:

Elephant size: 235  Elephant weight: 3568  Sample weight: 0.1  Elephant type: Asian
Elephant size: 321  Elephant weight: 4789  Sample weight: 0.1  Elephant type: African
Elephant size: 389  Elephant weight: 5689  Sample weight: 0.1  Elephant type: African
Elephant size: 210  Elephant weight: 2700  Sample weight: 0.1  Elephant type: Asian
Elephant size: 270  Elephant weight: 3654  Sample weight: 0.1  Elephant type: Asian
Elephant size: 289  Elephant weight: 3832  Sample weight: 0.1  Elephant type: African
Elephant size: 368  Elephant weight: 5976  Sample weight: 0.1  Elephant type: African
Elephant size: 291  Elephant weight: 4872  Sample weight: 0.1  Elephant type: Asian
Elephant size: 303  Elephant weight: 5132  Sample weight: 0.1  Elephant type: African
Elephant size: 246  Elephant weight: 2221  Sample weight: 0.1  Elephant type: African

我创建了一个分类器类:

import java.util.ArrayList;

public class Classifier {
private String feature;
private int treshold;
private double errorRate;
private double classifierWeight;

public void classify(Elephant elephant){
    if(feature.equals("size")){
        if(elephant.getSize()>treshold){
            elephant.setClassifiedAs(ElephantType.African);
        }
        else{
            elephant.setClassifiedAs(ElephantType.Asian);
        }           
    }
    else if(feature.equals("weight")){
        if(elephant.getWeight()>treshold){
            elephant.setClassifiedAs(ElephantType.African);
        }
        else{
            elephant.setClassifiedAs(ElephantType.Asian);
        }
    }
}

public void countErrorRate(ArrayList<Elephant> elephants){
    double misclassified = 0;
    for(int i=0;i<elephants.size();i++){
        if(elephants.get(i).getClassifiedAs().equals(elephants.get(i).getType()) == false){
            misclassified++;
        }
    }
    this.setErrorRate(misclassified/elephants.size());
}

public void countClassifierWeight(){
    this.setClassifierWeight(0.5*Math.log((1.0-errorRate)/errorRate));
}

public Classifier(String feature, int treshold){
    setFeature(feature);
    setTreshold(treshold);
}

我在 main() 中训练了一个按“大小”和阈值 = 250 进行分类的分类器,如下所示:

 main.trainAWeakClassifier("size", 250);

在我的分类器对每只大象进行分类后,我计算分类器错误,更新每个样本(大象)的权重并计算分类器的权重。我的问题是:

如何创建下一个分类器以及它如何更关心错误分类的样本(我知道样本权重是关键,但它是如何工作的,因为我不知道如何实现它)?我是否正确创建了第一个分类器?

4

1 回答 1

0

好吧,您计算错误率并可以对实例进行分类,但是您缺少的是分类器的更新并将它们按照 Ada Boost 公式组合成一个。看看这里的算法: 维基百科的 Ada Boost 网页

于 2012-08-29T04:44:22.107 回答