This transform converts numerical features into categorical ones via a simple histogram. Bins will be created for each numeric feature of equal sizes. Each numeric feature will be converted to the same number of bins. This transform will handle missing values by simply ignoring them, and leavin
| 22 | * @author Edward Raff |
| 23 | */ |
| 24 | public class NumericalToHistogram implements DataTransform |
| 25 | { |
| 26 | |
| 27 | private static final long serialVersionUID = -2318706869393636074L; |
| 28 | private int n; |
| 29 | //First index is the vector index, 2nd index is the min value then the increment value |
| 30 | double[][] conversionArray; |
| 31 | CategoricalData[] newDataArray; |
| 32 | |
| 33 | /** |
| 34 | * Creates a new transform which will use at most 25 bins when converting |
| 35 | * numeric features. This may not be optimal for any given dataset |
| 36 | * |
| 37 | */ |
| 38 | public NumericalToHistogram() |
| 39 | { |
| 40 | this(25); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Creates a new transform which will use O(sqrt(n)) bins for each numeric |
| 45 | * feature, where <i>n</i> is the number of data points in the dataset. |
| 46 | * |
| 47 | * @param dataSet the data set to create the transform from |
| 48 | */ |
| 49 | public NumericalToHistogram(DataSet dataSet) |
| 50 | { |
| 51 | this(dataSet, (int) Math.ceil(Math.sqrt(dataSet.getSampleSize()))); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Creates a new transform which will use at most the specified number of bins |
| 56 | * |
| 57 | * @param n the number of bins to create |
| 58 | */ |
| 59 | public NumericalToHistogram(int n) |
| 60 | { |
| 61 | setNumberOfBins(n); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Creates a new transform which will use the specified number of bins for |
| 66 | * each numeric feature. |
| 67 | * @param dataSet the data set to create the transform from |
| 68 | * @param n the number of bins to create |
| 69 | */ |
| 70 | public NumericalToHistogram(DataSet dataSet, int n) |
| 71 | { |
| 72 | this(n); |
| 73 | fit(dataSet); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void fit(DataSet dataSet) |
| 78 | { |
| 79 | conversionArray = new double[dataSet.getNumNumericalVars()][2]; |
| 80 | |
| 81 | double[] mins = new double[conversionArray.length]; |
nothing calls this directly
no outgoing calls
no test coverage detected