List of usage examples for weka.core.converters C45Loader FILE_EXTENSION
String FILE_EXTENSION
To view the source code for weka.core.converters C45Loader FILE_EXTENSION.
Click Source Link
From source file:lfsom.data.LFSData.java
License:Apache License
/** * Gets the data from a csv file./*from ww w .j a v a 2s . c o m*/ * * @param fileName */ public LFSData(String fileName) { Class claseCargador = CSVLoader.class; if (fileName.endsWith(ArffLoader.FILE_EXTENSION)) { claseCargador = ArffLoader.class; } else { if (fileName.endsWith(JSONLoader.FILE_EXTENSION)) { claseCargador = JSONLoader.class; } else { if (fileName.endsWith(MatlabLoader.FILE_EXTENSION)) { claseCargador = MatlabLoader.class; } else { if (fileName.endsWith(XRFFLoader.FILE_EXTENSION)) { claseCargador = XRFFLoader.class; } else { if (fileName.endsWith(C45Loader.FILE_EXTENSION)) { claseCargador = C45Loader.class; } } } } } try { AbstractFileLoader cargador = (AbstractFileLoader) claseCargador.getConstructor().newInstance(); boolean cambio_col = false; cargador.setSource(new File(fileName)); Instances data1 = cargador.getDataSet(); double[][] matrix2 = new double[data1.size()][data1.numAttributes()]; for (int i = 0; i < data1.size(); i++) { matrix2[i] = data1.get(i).toDoubleArray(); } // Ahora se comprueba si todas las columnas son ok Integer[] colVale; dim = 0; if (data1.size() > 0) { colVale = new Integer[matrix2[0].length]; double[] stdevX = StatisticSample.stddeviation(matrix2); for (int k = 0; k < matrix2[0].length; k++) { if (Math.abs(stdevX[k]) >= 0.000000001) { colVale[k] = dim; dim++; } else { colVale[k] = -1; cambio_col = true; } } } else { dim = data1.numAttributes(); colVale = new Integer[dim]; for (int k = 0; k < dim; k++) { colVale[k] = k; } } double[][] matrixAssign = new double[matrix2.length][dim]; if (cambio_col) { for (int k = 0; k < matrix2.length; k++) { for (int w = 0; w < matrix2[0].length; w++) { if (colVale[w] != -1) { matrixAssign[k][colVale[w]] = matrix2[k][w]; } } } } else { matrixAssign = matrix2; } // Fin de la comprobacion setLabels(new String[dim]); for (int i = 0; i < data1.numAttributes(); i++) { if (colVale[i] != -1) { getLabels()[colVale[i]] = data1.attribute(i).name(); } } BufferedWriter br = new BufferedWriter(new FileWriter("d:/tmp/fich.csv")); StringBuilder sb = new StringBuilder(); for (int i = 0; i < matrixAssign.length; i++) { String cad = String.valueOf(matrixAssign[i][0]); for (int k = 1; k < matrixAssign[i].length; k++) cad += "," + matrixAssign[i][k]; sb.append(cad + "\n"); } br.write(sb.toString()); br.close(); setMatrix(matrixAssign); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }