protected void loadClusterer() {
int returnVal = m_FileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File selected = m_FileChooser.getSelectedFile();
Clusterer clusterer = null;
Instances trainHeader = null;
int[] ignoredAtts = null;
m_Log.statusMessage("Loading model from file...");
try {
InputStream is = new FileInputStream(selected);
if (selected.getName().endsWith(".gz")) {
is = new GZIPInputStream(is);
}
ObjectInputStream objectInputStream = new ObjectInputStream(is);
clusterer = (Clusterer) objectInputStream.readObject();
try { // see if we can load the header & ignored attribute info
trainHeader = (Instances) objectInputStream.readObject();
ignoredAtts = (int[]) objectInputStream.readObject();
} catch (Exception e) {} // don't fuss if we can't
objectInputStream.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e, "Load Failed",
JOptionPane.ERROR_MESSAGE);
}
m_Log.statusMessage("OK");
if (clusterer != null) {
m_Log.logMessage("Loaded model from file '" + selected.getName()+ "'");
String name = (new SimpleDateFormat("HH:mm:ss - ")).format(new Date());
String cname = clusterer.getClass().getName();
if (cname.startsWith("weka.clusterers."))
cname = cname.substring("weka.clusterers.".length());
name += cname + " from file '" + selected.getName() + "'";
StringBuffer outBuff = new StringBuffer();
outBuff.append("=== Model information ===\n\n");
outBuff.append("Filename: " + selected.getName() + "\n");
outBuff.append("Scheme: " + clusterer.getClass().getName());
if (clusterer instanceof OptionHandler) {
String [] o = ((OptionHandler) clusterer).getOptions();
outBuff.append(" " + Utils.joinOptions(o));
}
outBuff.append("\n");
if (trainHeader != null) {
outBuff.append("Relation: " + trainHeader.relationName() + '\n');
outBuff.append("Attributes: " + trainHeader.numAttributes() + '\n');
if (trainHeader.numAttributes() < 100) {
boolean [] selectedAtts = new boolean [trainHeader.numAttributes()];
for (int i = 0; i < trainHeader.numAttributes(); i++) {
selectedAtts[i] = true;
}
if (ignoredAtts != null)
for (int i=0; i<ignoredAtts.length; i++)
selectedAtts[ignoredAtts[i]] = false;
for (int i = 0; i < trainHeader.numAttributes(); i++) {
if (selectedAtts[i]) {
outBuff.append(" " + trainHeader.attribute(i).name()
+ '\n');
}
}
if (ignoredAtts != null) {
outBuff.append("Ignored:\n");
for (int i=0; i<ignoredAtts.length; i++)
outBuff.append(" "
+ trainHeader.attribute(ignoredAtts[i]).name()
+ '\n');
}
} else {
outBuff.append(" [list of attributes omitted]\n");
}
} else {
outBuff.append("\nTraining data unknown\n");
}
outBuff.append("\n=== Clustering model ===\n\n");
outBuff.append(clusterer.toString() + "\n");
m_History.addResult(name, outBuff);
m_History.setSingle(name);
FastVector vv = new FastVector();
vv.addElement(clusterer);