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);
}
我在主訓練的(),它由「大小」和treshold = 250就是這樣的分類的分類:
main.trainAWeakClassifier("size", 250);
在我的分類器對每個大象進行分類後,我計算分類器錯誤,更新每個樣本(大象)的權重並計算分類器的權重。我的問題是:
如何創建下一個分類器,以及它如何關心錯誤分類的樣本(我知道樣本權重是關鍵,但它是如何工作的,因爲我不知道如何實現它)? 我是否正確創建了第一個分類器?
如果你正在與大象合作,你可能想嘗試一個強大的學習者。你如何期望一個弱小的人能夠處理一個5噸的哺乳動物? – thkala
我真的不明白你的意思,但我很欣賞你的幽默感。 AdaBoost基於弱學習者。 – AjMeen
你需要從頭開始實施它,還是可以使用像Weka或R這樣的libreries? –