@Override public void actionPerformed(ActionEvent e) { if ( fc.showOpenDialog(ClassifyTabOptions.this) == JFileChooser.APPROVE_OPTION) { try { m_FileTestset = DataSource.read(new FileInputStream(fc.getSelectedFile())); } catch(Exception exp) { System.err.println("[Error] Failed to load file."); exp.printStackTrace(); } } } });
/** * for testing only - takes a data file as input and a data file for the * output. * * @param args the commandline arguments * @throws Exception if something goes wrong */ public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println("\nUsage: " + DataSource.class.getName() + " <input-file> <output-file>\n"); System.exit(1); } // load data Instances data = DataSource.read(args[0]); // save data DataSink.write(args[1], data); }
public static void main(String[] args) throws Exception { if (args.length != 1) throw new IllegalArgumentException("Required arguments: <dataset>"); System.out.println("Loading data: " + args[0]); Instances data = DataSource.read(args[0]); MLUtils.prepareData(data); int numFolds = 10; System.out.println("Cross-validate BR classifier using " + numFolds + " folds"); BR classifier = new BR(); // further configuration of classifier String top = "PCut1"; String vop = "3"; Result result = Evaluation.cvModel(classifier, data, numFolds, top, vop); System.out.println(result); } }
/** * Builds the classifier for the given training model */ private void initializeModel(CommonConfig config) throws ConfigurationException { // Train the classifier logger.info("Training the classifier..."); File arffFile = new File(modelDir + "/" + this.getClass().getSimpleName() + ".arff"); classifier = new NaiveBayes(); try { Instances data = DataSource.read(arffFile.getAbsolutePath()); data.setClassIndex(data.numAttributes() - 1); classifier.buildClassifier(data); } catch (Exception e) { throw new ConfigurationException(e); } }
private Instances getTrainInstances(File trainArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(trainArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
public static void main(String[] args) throws Exception { if (args.length != 3) throw new IllegalArgumentException("Required parameters: <input> <attribute_indices> <output>"); System.out.println("Loading input data: " + args[0]); Instances input = DataSource.read(args[0]); System.out.println("Applying filter using indices: " + args[1]); MekaClassAttributes filter = new MekaClassAttributes(); filter.setAttributeIndices(args[1]); filter.setInputFormat(input); Instances output = Filter.useFilter(input, filter); System.out.println("Saving filtered data to: " + args[2]); ArffSaver saver = new ArffSaver(); saver.setFile(new File(args[2])); DataSink.write(saver, output); } }
private Instances getTrainInstances(File trainArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(trainArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTrainInstances(File trainArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(trainArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTestInstances(File testArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(testArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTrainInstances(File trainArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(trainArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTestInstances(File testArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(testArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTestInstances(File testArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(testArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTestInstances(File testArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(testArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTestInstances(File testArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(testArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTrainInstances(File trainArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(trainArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTrainInstances(File trainArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(trainArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
private Instances getTestInstances(File testArff) throws SimilarityException { // Read with Weka Instances data; try { data = DataSource.read(testArff.getAbsolutePath()); } catch (Exception e) { throw new SimilarityException(e); } // Set the index of the class attribute data.setClassIndex(data.numAttributes() - 1); return data; }
/** * Called by JUnit before each test method. * * @throws Exception if an error occurs */ protected void setUp() throws Exception { super.setUp(); m_Instances = DataSource.read(ClassLoader.getSystemResourceAsStream("weka/core/data/InstancesTest.arff")); }
/** * Called by JUnit before each test method. * * @throws Exception if an error occurs */ protected void setUp() throws Exception { super.setUp(); m_Instances = DataSource.read(ClassLoader.getSystemResourceAsStream("weka/core/data/InstancesTest.arff")); }
public static void main(String[] args) throws Exception { if (args.length != 1) throw new IllegalArgumentException("Required arguments: <dataset>"); System.out.println("Loading data: " + args[0]); Instances data = DataSource.read(args[0]); MLUtils.prepareData(data); System.out.println("Build BR classifier"); BR classifier = new BR(); // further configuration of classifier classifier.buildClassifier(data); } }