00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 package de.picana.classifier;
00014
00015 import de.picana.control.*;
00016 import de.picana.logging.*;
00017 import de.picana.clusterer.*;
00018 import de.picana.math.*;
00019
00020 import weka.core.*;
00021 import java.io.*;
00022 import java.util.*;
00023
00024
00031 public class SimpleKMeans extends Classifier {
00032
00033 weka.clusterers.SimpleKMeans algo;
00034
00036 public SimpleKMeans() {
00037 }
00038
00039 protected void loadModel(String filename) throws TaskException {
00040 try {
00041 File model = new File(filename);
00042 FileInputStream fmis = new FileInputStream(model);
00043 ObjectInputStream in = new ObjectInputStream(fmis);
00044
00045 num_clusters = in.readInt();
00046 algo = (weka.clusterers.SimpleKMeans)in.readObject();
00047 in.close();
00048
00049 } catch (Exception e) {
00050 throw new TaskException(e.toString());
00051 }
00052 }
00053
00054 protected int classify(Instance i) {
00055 int cl = -1;
00056 try {
00057 cl = algo.clusterInstance(i);
00058 } catch (Exception e) {
00059 }
00060 return cl;
00061 }
00062 }