Java 类weka.core.converters.ArffLoader 实例源码

项目:reactive-data    文件:CombinerDatasetGenerator.java   
@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);
}
项目:jbossBA    文件:Main.java   
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
}
项目:Android-Context-Framework    文件:WekaManager.java   
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();
        }
    }
项目:bestconf    文件:DataIOFile.java   
/**
 * 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;
}
项目:BestConfig    文件:DataIOFile.java   
/**
 * 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;
}
项目:Data-curation-API    文件:ExtractClassificationTextRandomForestImpl.java   
@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();
}
项目:Data-curation-API    文件:ExtractClassificationTextNaiveBaysImpl.java   
@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();
}
项目:Data-curation-API    文件:ExtractClassificationTextKNNImpl.java   
@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();
}
项目:Data-curation-API    文件:ExtractClassificationTextSVMImpl.java   
@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();

}
项目:Data-curation-API    文件:ExtractClassificationTextNeuralNetworkImpl.java   
@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();
}
项目:Data-curation-API    文件:ExtractClassificationTextDecisionTreeImpl.java   
@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();     
}
项目:Data-curation-API    文件:ExtractClassificationTextLogisticRegressionImpl.java   
@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();

}
项目:Data-curation-API    文件:TextClassifier.java   
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();
}
项目:OntologyBasedInormationExtractor    文件:ArffUtil.java   
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);
    }
}
项目:LibD3C-1.1    文件:InstanceUtil.java   
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;
}
项目:WAIDRecognizer    文件:ModelManager.java   
/**
 * 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;
}
项目:mathosphere    文件:WekaLearner.java   
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;
}
项目:mHealthDroid    文件:Classification.java   
/**
 * 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();
    }
}
项目:vimarsha    文件:ArffAttributeInfoExtractor.java   
/**
 * 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();
}
项目:autoweka    文件:Util.java   
public static Instances loadDataSource(java.io.InputStream stream) throws Exception
{
    ArffLoader loader = new ArffLoader();
    loader.setSource(stream);
    return loader.getDataSet();
}
项目:gap    文件:MutualInformationMain.java   
/**
 * 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;
}