@PostConstruct private void init() { try { ArffLoader loader = new ArffLoader(); File f = ResourceUtils.getFile(dummyFile); loader.setFile(f); log.info("Reading file ["+f+"] for creating evaluation dataset"); instances = loader.getDataSet(); } catch (Exception e) { log.error("EvaluationDatasetGenerator::init [ "+e.getMessage() + "] Will go with a dummy dataset. "); log.debug("", e); try { instances = new RandomRBF().generateExamples(); } catch (Exception e1) { log.debug("", e); } } instances.setClassIndex(instances.numAttributes()-1); }
public void run() throws Exception { // data ArffLoader arffLoader = new ArffLoader(); arffLoader.setSource(new File("/home/bhill/apps/weka/weka-3-6-11/data/soybean.arff")); Instances data = arffLoader.getDataSet(); data.setClassIndex(data.numAttributes()-1); J48 j48 = new J48(); j48.buildClassifier(data); // j48.m_root.m_sons System.out.println(); // J48.train() // check for nodes }
public void configureWithArffFile(File file) { if (FrameworkContext.INFO) Log.i(TAG, "Loading from path: " + file.getPath()); try { ArffLoader loader = new ArffLoader(); loader.setSource(file); trainingData = loader.getDataSet(); if (FrameworkContext.INFO) Log.i(TAG, "WEKA configuration from ARFF File: " + file.getPath() + "Training Data Information:\n" + trainingData.toSummaryString()); buildClassifier(); } catch (Exception e) { e.printStackTrace(); } }
/** * Return the data set loaded from the Arff file at @param path */ public static Instances loadDataFromArffFile(String path) throws IOException{ ArffLoader loader = new ArffLoader(); loader.setSource(new File(path)); Instances data = loader.getDataSet(); System.out.println("\nHeader of dataset:\n"); System.out.println(new Instances(data, 0)); return data; }
@Override public void LoadDataset(File arffFileName) throws IOException { BufferedReader bReader=new BufferedReader( new FileReader(arffFileName)); ArffLoader.ArffReader arff=new ArffLoader.ArffReader(bReader); trainedData=arff.getData(); bReader.close(); }
@Override public void LoadDataset(File arffFileName) throws IOException { BufferedReader bReader=new BufferedReader(new FileReader(arffFileName)); ArffLoader.ArffReader arff=new ArffLoader.ArffReader(bReader); trainedData=arff.getData(); bReader.close(); }
public void LoadTestData(File ArffFileName) throws FileNotFoundException, IOException { BufferedReader bTestReader=new BufferedReader( new FileReader(ArffFileName)); ArffLoader.ArffReader myarff=new ArffLoader.ArffReader(bTestReader); test=myarff.getData(); bTestReader.close(); }
public static Instances loadArff(String path) throws ClassifierException { ArffLoader loader = new ArffLoader(); File arffFile = new File(path); try { loader.setFile(arffFile); return loader.getDataSet(); } catch (IOException e) { throw new ClassifierException("Loading arff file failed", e); } }
public static Instances getInstances(File file) throws Exception { Instances inst = null; try { ArffLoader loader = new ArffLoader(); loader.setFile(file); inst = loader.getDataSet(); } catch (Exception e) { throw new Exception(e.getMessage()); } return inst; }
/** * Read the vehicle data from a .arff file and return it as a list of * instances * * @param file * a valid .arff file * @return the list of instances * @throws IOException * if the file is not a valid .arff file */ public static ArrayList<VehicleInstance> readArffFile(File file) throws IOException { ArrayList<VehicleInstance> instances = new ArrayList<VehicleInstance>(); ArffLoader arffLoader = new ArffLoader(); // Get the instances from the file arffLoader.setSource(file); Instances wekaInstances = arffLoader.getDataSet(); wekaInstances.setClassIndex(wekaInstances.numAttributes() - 1); for (int i = 0; i < wekaInstances.numInstances(); i++) { // Convert the Instance in a VehicleInstance VehicleInstance vehicleInstance = new VehicleInstance(); MagnitudeFeatures accelFeatures = new MagnitudeFeatures(); MagnitudeFeatures gyroFeatures = new MagnitudeFeatures(); Instance currentInstance = wekaInstances.instance(i); accelFeatures.setAverage(currentInstance.value(0)); accelFeatures.setMaximum(currentInstance.value(2)); accelFeatures.setMinimum(currentInstance.value(4)); accelFeatures.setStandardDeviation(currentInstance.value(6)); gyroFeatures.setAverage(currentInstance.value(1)); gyroFeatures.setMaximum(currentInstance.value(3)); gyroFeatures.setMinimum(currentInstance.value(5)); gyroFeatures.setStandardDeviation(currentInstance.value(7)); vehicleInstance.setAccelFeatures(accelFeatures); vehicleInstance.setGyroFeatures(gyroFeatures); vehicleInstance.setCategory(currentInstance.toString(8)); // Add the instance to the list instances.add(vehicleInstance); } return instances; }
public List<EvaluationResult> processFromInstances() throws Exception { BufferedReader reader = new BufferedReader(new FileReader(config.getInstancesFile())); ArffLoader.ArffReader arff = new ArffLoader.ArffReader(reader); Instances instances; instances = arff.getData(); instances.setClassIndex(instances.numAttributes() - 1); ArrayList<EvaluationResult> evaluationResults = new ArrayList<>(); //wrap Collector<EvaluationResult> c = new ListCollector<>(evaluationResults); process(c, instances); return evaluationResults; }
/** * Method to read a weka file * @param dir directory file * @param fileName arff file name */ public void readFile(File dir, String fileName) { File file = new File(dir, fileName); // StringBuilder texto = readFile(file); // return texto; atf = new ArffLoader(); try { atf.setFile(file); } catch (IOException e) { Log.d("ERROR", "Error 1"); e.printStackTrace(); } }
/** * Creates a new arff attribute extractor. * * @param fileToOpen File to open * @param performanceEventsHolder PerformanceEventsHolder * @throws IOException */ public ArffAttributeInfoExtractor(File fileToOpen, PerformanceEventsHolder performanceEventsHolder) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(fileToOpen)); this.arffReader = new ArffLoader.ArffReader(reader); this.performanceEventsHolder = performanceEventsHolder; this.arffData = this.arffReader.getData(); this.arffStructure = this.arffReader.getStructure(); reader.close(); }
public static Instances loadDataSource(java.io.InputStream stream) throws Exception { ArffLoader loader = new ArffLoader(); loader.setSource(stream); return loader.getDataSet(); }
/** * Read the arff file provided as parameter and returns the dataset as a WEKA's Istances object. * @param file file to be opened * @return The dataset as a WEKA's Istances object * @throws IOException if something wrong */ public static Instances readArff(File file) throws IOException { LOGGER.log( Level.INFO, "Reading the arff file, which path: {0} ", file.getAbsolutePath() ); BufferedReader reader = new BufferedReader(new FileReader(file)); ArffLoader.ArffReader arff = new ArffLoader.ArffReader(reader); Instances data = arff.getData(); //data.setClassIndex(data.numAttributes() - 1); LOGGER.log( Level.FINE, "Read {0} instances", data.numInstances() ); return data; }