List of usage examples for weka.classifiers UpdateableClassifier updateClassifier
void updateClassifier(Instance instance) throws Exception;
From source file:com.reactivetechnologies.analytics.core.IncrementalClassifierBean.java
License:Open Source License
@Override public void buildClassifier(Instances data) throws Exception { try {/*w ww. j a v a 2 s . c o m*/ if (isUpdateable()) { UpdateableClassifier u = (UpdateableClassifier) clazzifier; for (@SuppressWarnings("unchecked") Enumeration<Instance> e = data.enumerateInstances(); e.hasMoreElements();) { u.updateClassifier(e.nextElement()); } } else clazzifier.buildClassifier(data); lastBuildAt = System.currentTimeMillis(); } finally { } }
From source file:gnusmail.learning.ClassifierManager.java
License:Open Source License
/** * This method reads the messages in chronological order, and updates the * underlying model with each message/* www .j a v a 2 s . c om*/ * * @return */ public List<Double> incrementallyTrainModel(DocumentReader reader, String wekaClassifier, FilterManager fm) { List<Double> successes = new ArrayList<Double>(); try { Classifier model = null; model = (Classifier) Class.forName(wekaClassifier).newInstance(); try { model.buildClassifier(filterManager.getDataset()); } catch (Exception ex) { Logger.getLogger(ClassifierManager.class.getName()).log(Level.SEVERE, null, ex); } UpdateableClassifier updateableModel = (UpdateableClassifier) model; for (Document doc : reader) { double predictedClass = 0.0; try { Instance inst = doc.toWekaInstance(fm); predictedClass = model.classifyInstance(inst); double trueClass = inst.classValue(); successes.add((predictedClass == trueClass) ? 1.0 : 0.0); updateableModel.updateClassifier(inst); } catch (Exception ex) { Logger.getLogger(ClassifierManager.class.getName()).log(Level.SEVERE, null, ex); } } FileOutputStream f = new FileOutputStream(ConfigManager.MODEL_FILE); ObjectOutputStream fis = new ObjectOutputStream(f); fis.writeObject(updateableModel); fis.close(); } catch (Exception ex) { Logger.getLogger(ClassifierManager.class.getName()).log(Level.SEVERE, null, ex); } return successes; }
From source file:gnusmail.learning.ClassifierManager.java
License:Open Source License
public void updateModelWithDocument(Document document) { Reader r = null;//from ww w . j a va 2 s .c om try { Instance inst = document.toWekaInstance(filterManager); Classifier model; FileInputStream fe = new FileInputStream(ConfigManager.MODEL_FILE); ObjectInputStream fie = new ObjectInputStream(fe); model = (Classifier) fie.readObject(); UpdateableClassifier updateableModel = (UpdateableClassifier) model; updateableModel.updateClassifier(inst); FileOutputStream f = new FileOutputStream(ConfigManager.MODEL_FILE); ObjectOutputStream fis = new ObjectOutputStream(f); fis.writeObject(updateableModel); fis.close(); System.out.println("Model updated"); } catch (Exception ex) { Logger.getLogger(ClassifierManager.class.getName()).log(Level.SEVERE, null, ex); } finally { try { r.close(); } catch (IOException ex) { Logger.getLogger(ClassifierManager.class.getName()).log(Level.SEVERE, null, ex); } } }