List of usage examples for weka.gui.explorer ClassifierPanel PMML_FILE_EXTENSION
String PMML_FILE_EXTENSION
To view the source code for weka.gui.explorer ClassifierPanel PMML_FILE_EXTENSION.
Click Source Link
From source file:trainableSegmentation.WekaSegmentation.java
License:GNU General Public License
/** * Read header classifier from a .model file * @param filename complete path and file name * @return false if error/*from ww w. j a va2 s .c om*/ */ public boolean loadClassifier(String filename) { AbstractClassifier newClassifier = null; Instances newHeader = null; File selected = new File(filename); try { InputStream is = new FileInputStream(selected); if (selected.getName().endsWith(ClassifierPanel.PMML_FILE_EXTENSION)) { PMMLModel model = PMMLFactory.getPMMLModel(is, null); if (model instanceof PMMLClassifier) newClassifier = (PMMLClassifier) model; else throw new Exception("PMML model is not a classification/regression model!"); } else { if (selected.getName().endsWith(".gz")) is = new GZIPInputStream(is); ObjectInputStream objectInputStream = new ObjectInputStream(is); newClassifier = (AbstractClassifier) objectInputStream.readObject(); try { // see if we can load the header newHeader = (Instances) objectInputStream.readObject(); } catch (Exception e) { IJ.error("Load Failed", "Error while loading train header"); return false; } finally { objectInputStream.close(); } } } catch (Exception e) { IJ.error("Load Failed", "Error while loading classifier"); e.printStackTrace(); return false; } try { // Check if the loaded information corresponds to current state of the segmentator // (the attributes can be adjusted, but the classes must match) if (false == adjustSegmentationStateToData(newHeader)) { IJ.log("Error: current segmentator state could not be updated to loaded data requirements (attributes and classes)"); return false; } } catch (Exception e) { IJ.log("Error while adjusting data!"); e.printStackTrace(); return false; } this.classifier = newClassifier; this.trainHeader = newHeader; return true; }