Here you can find the source of equalFreqBinning(double[][] sampleData, int numPredVals, int numRespVals, int divInd)
Parameter | Description |
---|---|
sampleData | a parameter |
numVals | a parameter |
public static void equalFreqBinning(double[][] sampleData, int numPredVals, int numRespVals, int divInd)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { /**/* ww w.j a va 2 s. c o m*/ * Performs a simple binning of the response values. It will result in the * values becoming integers in the range [0,numVals-1]. * * @param sampleData * @param numVals */ public static void equalFreqBinning(double[][] sampleData, int numPredVals, int numRespVals, int divInd) { if (sampleData.length > 0) { double[][] inds = new double[sampleData[0].length][Math.max(numPredVals, numRespVals)]; int num = numPredVals; for (int r = 0; r < sampleData[0].length; r++) { if (r == divInd) { num = numRespVals; } double[] singleData = new double[sampleData.length]; for (int i = 0; i < sampleData.length; i++) { singleData[i] = sampleData[i][r]; } Arrays.sort(singleData); for (int i = 0; i < num; i++) { inds[r][i] = singleData[i * singleData.length / num]; } } for (double[] sample : sampleData) { for (int i = 0; i < divInd; i++) { int val = 1; while (val < numPredVals && inds[i][val] < sample[i]) { val++; } sample[i] = val - 1.0; } for (int i = divInd; i < sample.length; i++) { int val = 1; while (val < numRespVals && inds[i][val] < sample[i]) { val++; } sample[i] = val - 1.0; } } } } }