将.data文件转换为.idx文件以获取数据集

时间:2018-02-03 12:55:31

标签: java dataset arff idx

我有一个后缀为.data和.dat的文件作为我的数据集,我需要将其转换为.idx和.arrf以将其用作输入。我需要它用于我的java项目,我会感激你的掌控。这是我的数据样本: lib.stat.cmu.edu/datasets/NO2.dat

  BufferedReader r = new BufferedReader(new FileReader("data.arff"));
  Instances data = new Instances(r);
  data.setClassIndex(data.numAttributes() - 1);
  normalize(data);
  r.close();

  /* The data.idx must contain 3 serialized integer array obects.
   * They contain the instance indeies in the data file that belong to, respectively,
   * the labeled set, the unlabeled set and the test set
   */
  ObjectInputStream objin = new ObjectInputStream(new FileInputStream("data.idx"));
  int[] labeledIdx = (int[]) objin.readObject();
  int[] unlabeledIdx = (int[]) objin.readObject();
  int[] testIdx = (int[]) objin.readObject();

  Instances labeled = new Instances(data, 0);
  Instances unlabeled = new Instances(data, 0);
  Instances test = new Instances(data, 0);

0 个答案:

没有答案