Klassifizierung Einzige Instanz in Weka

Ich trainiert habe und erstellt eine J48-Modell mit WEKA-gui. Ich speicherte die Modell-Datei auf meinem Rechner und jetzt möchte ich es verwenden, um zu klassifizieren, eine einzelne Instanz, in meinem Java-code. Ich würde gerne eine Vorhersage für das Attribut "cluster". Was ich Tue ist das folgende:

public void classify(double lat, double lon, double co)
{            

//Create attributes to be used with classifiers
                    Attribute latitude = new Attribute("latitude");
                    Attribute longitude = new Attribute("longitude");
                    Attribute carbonmonoxide = new Attribute("co");

                    //Create instances for each pollutant with attribute values latitude, longitude and pollutant itself
                    inst_co = new DenseInstance(4);

                    //Set instance's values for the attributes "latitude", "longitude", and "pollutant concentration"
                    inst_co.setValue(latitude, lat);
                    inst_co.setValue(longitude, lon);
                    inst_co.setValue(carbonmonoxide, co);
                    inst_co.setMissing(cluster);


    Classifier cls_co = (Classifier) weka.core.SerializationHelper.read("/CO_J48Model.model");//load classifier from file

                    //Test the model
        double result = cls_co.classifyInstance(inst_co);
}

Allerdings bekomme ich eine IndexArrayOutofBoundsException auf der Linie inst_co.setValue(latitude, lat);. Ich konnte nicht finden, dass der Grund für diese Ausnahme. Ich werde es begrüßen, wenn jemand könnte mich in die richtige Richtung.

InformationsquelleAutor Erol | 2012-10-23
Schreibe einen Kommentar