当要转换的文件中存在非法字符时,经常会出现这个问题。你可以仔细检查是否有这样的字符。你也可以使用下面的代码在java中进行csv到arff的转换。
import weka.core.Instances;
import weka.core.converters.ArffSaver;
import weka.core.converters.CSVLoader;
import java.io.File;
public class CsvtoArff {
public static void main(String[] args) throws Exception {
String args0="/Users/Kehinde/Documents/trainingtest.csv";
String args1="/Users/Kehinde/Documents/theoutput.arff";
// This is used to load CSV
CSVLoader myloader = new CSVLoader();
myloader.setSource(new File(args0));
Instances mydata = myloader.getDataSet();
System.out.println(mydata);
// This is used to save ARFF
ArffSaver mysaver = new ArffSaver();
mysaver.setInstances(mydata);
mysaver.setFile(new File(args1));
mysaver.setDestination(new File(args1));
mysaver.writeBatch();
}
}