List of usage examples for weka.core MOAUtils toCommandLine
public static String toCommandLine(MOAObject obj)
From source file:moa.classifiers.AbstractClassifierTestCase.java
License:Open Source License
/** * Saves the data in the tmp directory./*w w w. j av a 2 s. co m*/ * * @param data the data to save * @param filename the filename to save to (without path) * @return true if successfully saved */ protected boolean save(Classifier cls, InspectionData[] data, String filename) { StringBuilder str; str = new StringBuilder(); str.append(MOAUtils.toCommandLine(cls) + "\n"); str.append("\n"); for (InspectionData d : data) { str.append(d.toString()); str.append("\n"); } return m_TestHelper.save(str, filename); }
From source file:moa.classifiers.AbstractClassifierTestCase.java
License:Open Source License
/** * Compares the processed data against previously saved output data. *///from w ww . j av a 2 s.com public void testRegression() { Instances data; InspectionData[] processed; boolean ok; String regression; int i; String[] input; int[] cindices; Classifier[] setups; LearningPerformanceEvaluator<Example<Instance>>[] evals; int[][] points; Classifier current; String[] output; TmpFile[] outputFiles; if (m_NoRegressionTest) return; input = getRegressionInputFiles(); cindices = getRegressionInputClassIndex(); output = new String[input.length]; setups = getRegressionClassifierSetups(); evals = getRegressionEvaluatorSetups(); points = getRegressionInspectionPoints(); assertEquals("Number of files and class indices differ!", input.length, cindices.length); assertEquals("Number of files and classifier setups differ!", input.length, setups.length); assertEquals("Number of classifier setups and evaluator setups differ!", setups.length, evals.length); assertEquals("Number of classifier setups and inspection points differ!", setups.length, points.length); // process data for (i = 0; i < input.length; i++) { data = load(input[i], cindices[i]); assertNotNull("Could not load data for regression test from " + input[i], data); current = setups[i].copy(); current.prepareForUse(); current.setModelContext(new InstancesHeader(data)); assertNotNull("Failed to create copy of algorithm: " + MOAUtils.toCommandLine(setups[i]), current); processed = inspect(data, points[i], evals[i], current); assertNotNull("Failed to process data?", processed); output[i] = createOutputFilename(input[i], i); ok = save(current, processed, output[i]); assertTrue("Failed to save regression data?", ok); } // test regression outputFiles = new TmpFile[output.length]; for (i = 0; i < output.length; i++) outputFiles[i] = new TmpFile(output[i]); regression = m_Regression.compare(outputFiles); assertNull("Output differs:\n" + regression, regression); // remove output for (i = 0; i < output.length; i++) m_TestHelper.deleteFileFromTmp(output[i]); }
From source file:moa.classifiers.AbstractInstanceLearnerTestCase.java
License:Open Source License
/** * Saves the data in the tmp directory.//from ww w .j a v a 2 s. c o m * * @param data the data to save * @param filename the filename to save to (without path) * @return true if successfully saved */ protected boolean save(MLTask cls, InspectionData[] data, String filename) { StringBuilder str; str = new StringBuilder(); str.append(MOAUtils.toCommandLine(cls) + "\n"); str.append("\n"); for (InspectionData d : data) { str.append(d.toString()); str.append("\n"); } return m_TestHelper.save(str, filename); }
From source file:moa.classifiers.AbstractInstanceLearnerTestCase.java
License:Open Source License
/** * Compares the processed data against previously saved output data. *///w w w . ja va 2 s . c o m public void testRegression() { InstancesHeader data; InspectionData[] processed; boolean ok; String regression; int i; String[] input; int[] cindices; MLTask[] setups; LearningPerformanceEvaluator<Example<Instance>>[] evals; int[][] points; MLTask current; String[] output; TmpFile[] outputFiles; if (m_NoRegressionTest) return; input = getRegressionInputFiles(); cindices = getRegressionInputClassIndex(); output = new String[input.length]; setups = getLearnerSetups(); evals = getRegressionEvaluatorSetups(); points = getRegressionInspectionPoints(); assertEquals("Number of files and class indices differ!", input.length, cindices.length); assertEquals("Number of files and classifier setups differ!", input.length, setups.length); assertEquals("Number of classifier setups and evaluator setups differ!", setups.length, evals.length); assertEquals("Number of classifier setups and inspection points differ!", setups.length, points.length); // process data for (i = 0; i < input.length; i++) { data = load(input[i], cindices[i]); assertNotNull("Could not load data for regression test from " + input[i], data); current = this.copySetup(setups[i]); current.prepareForUse(); current.setModelContext(new InstancesHeader(data)); assertNotNull("Failed to create copy of algorithm: " + MOAUtils.toCommandLine(setups[i]), current); processed = inspect(data, points[i], evals[i], current); assertNotNull("Failed to process data?", processed); output[i] = createOutputFilename(input[i], i); ok = save(current, processed, output[i]); assertTrue("Failed to save regression data?", ok); } // test regression outputFiles = new TmpFile[output.length]; for (i = 0; i < output.length; i++) outputFiles[i] = new TmpFile(output[i]); regression = m_Regression.compare(outputFiles); assertNull("Output differs:\n" + regression, regression); // remove output for (i = 0; i < output.length; i++) m_TestHelper.deleteFileFromTmp(output[i]); }