WEKA GUIを使用してJ48モデルを訓練して作成しました。私はモデルファイルを自分のコンピュータに保存しましたが、今はJavaコードで単一のインスタンスを分類するためにモデルファイルを使用したいと思います。私は属性 "クラスタ"の予測を取得したいと思います。しかし、私はラインinst_co.setValue(latitude, lat);
にIndexArrayOutofBoundsExceptionを取得Wekaでの単一インスタンスの分類
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);
}
:私は何をするには、次のです。私はこの例外の理由を見つけることができませんでした。私は誰かが正しい方向に私を指すことができれば感謝します。
偉大な答えをありがとう。明確にするために、classAとclassBは分類の可能な結果、つまり私のクラスタ名ですか?私は彼らがモデルを作成している間に使用されたものと同じである必要があると思います。 – Erol
私はweka.core.UnassignedDatasetExceptionが発生しています:DenseInstanceはデータセットにアクセスできません!エラー。私はそれをデータセットに割り当てなければならないでしょう。 – Erol
@babatenor同じヘッダーを持つデータセットに割り当てる必要があります。彼らのヘッダー情報は同じでなければなりません –