List of usage examples for org.apache.commons.math.stat.correlation SpearmansCorrelation getCorrelationMatrix
public RealMatrix getCorrelationMatrix()
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.svmlib.regression.SVMLibRegressionExperimentRunner.java
@Override public void runCrossValidation(File dataDir) throws IOException { Set<SinglePrediction> allPredictions = new HashSet<SinglePrediction>(); List<File> files = new ArrayList<File>(FileUtils.listFiles(dataDir, new String[] { "libsvm.txt" }, false)); for (File testFile : files) { // create training files from the rest Set<File> trainingFiles = new HashSet<File>(files); trainingFiles.remove(testFile);// w ww . ja v a 2s . c om // System.out.println("Training files: " + trainingFiles); System.out.println("Training files size: " + trainingFiles.size()); System.out.println("Test file: " + testFile); Set<SinglePrediction> predictions = runSingleFold(testFile, new ArrayList<File>(trainingFiles)); allPredictions.addAll(predictions); } List<SinglePrediction> predictions = new ArrayList<SinglePrediction>(allPredictions); double[][] matrix = new double[predictions.size()][]; for (int i = 0; i < predictions.size(); i++) { SinglePrediction prediction = predictions.get(i); matrix[i] = new double[2]; matrix[i][0] = Double.valueOf(prediction.getGold()); matrix[i][1] = Double.valueOf(prediction.getPrediction()); } PearsonsCorrelation pearsonsCorrelation = new PearsonsCorrelation(matrix); try { double pValue = pearsonsCorrelation.getCorrelationPValues().getEntry(0, 1); double correlation = pearsonsCorrelation.getCorrelationMatrix().getEntry(0, 1); System.out.println("Correlation: " + correlation); System.out.println("p-Value: " + pValue); System.out.println("Samples: " + predictions.size()); SpearmansCorrelation sc = new SpearmansCorrelation(new Array2DRowRealMatrix(matrix)); double pValSC = sc.getRankCorrelation().getCorrelationPValues().getEntry(0, 1); double corrSC = sc.getCorrelationMatrix().getEntry(0, 1); System.out.println("Spearman: " + corrSC + ", p-Val " + pValSC); } catch (MathException e) { throw new IOException(e); } }