List of usage examples for weka.clusterers ClusterEvaluation evaluateClusterer
public void evaluateClusterer(Instances test, String testFileName, boolean outputModel) throws Exception
From source file:adams.flow.transformer.WekaTestSetClustererEvaluator.java
License:Open Source License
/** * Executes the flow item./*w w w.j av a 2 s. c o m*/ * * @return null if everything is fine, otherwise error message */ @Override protected String doExecute() { String result; Instances test; ClusterEvaluation eval; weka.clusterers.Clusterer cls; CallableSource gs; Token output; result = null; try { // get test set test = null; gs = new CallableSource(); gs.setCallableName(m_Testset); gs.setParent(getParent()); gs.setUp(); gs.execute(); output = gs.output(); if (output != null) test = (Instances) output.getPayload(); else result = "No test set available!"; gs.wrapUp(); // evaluate clusterer if (result == null) { if (m_InputToken.getPayload() instanceof weka.clusterers.Clusterer) cls = (weka.clusterers.Clusterer) m_InputToken.getPayload(); else cls = (weka.clusterers.Clusterer) ((WekaModelContainer) m_InputToken.getPayload()) .getValue(WekaModelContainer.VALUE_MODEL); eval = new ClusterEvaluation(); eval.setClusterer(cls); eval.evaluateClusterer(test, null, m_OutputModel); m_OutputToken = new Token(new WekaClusterEvaluationContainer(eval, cls)); } } catch (Exception e) { m_OutputToken = null; result = handleException("Failed to evaluate: ", e); } if (m_OutputToken != null) updateProvenance(m_OutputToken); return result; }
From source file:adams.flow.transformer.WekaTrainTestSetClustererEvaluator.java
License:Open Source License
/** * Executes the flow item./*from ww w . j av a 2 s .c om*/ * * @return null if everything is fine, otherwise error message */ @Override protected String doExecute() { String result; Instances train; Instances test; weka.clusterers.Clusterer cls; ClusterEvaluation eval; WekaTrainTestSetContainer cont; result = null; try { // cross-validate clusterer cls = getClustererInstance(); if (cls == null) throw new IllegalStateException("Clusterer '" + getClusterer() + "' not found!"); cont = (WekaTrainTestSetContainer) m_InputToken.getPayload(); train = (Instances) cont.getValue(WekaTrainTestSetContainer.VALUE_TRAIN); test = (Instances) cont.getValue(WekaTrainTestSetContainer.VALUE_TEST); cls.buildClusterer(train); eval = new ClusterEvaluation(); eval.setClusterer(cls); eval.evaluateClusterer(test, null, m_OutputModel); // broadcast result m_OutputToken = new Token(new WekaClusterEvaluationContainer(eval, cls)); } catch (Exception e) { m_OutputToken = null; result = handleException("Failed to evaluate: ", e); } if (m_OutputToken != null) updateProvenance(m_OutputToken); return result; }