Performing a transform on the whole data set before training a classifier can add bias to the results. For proper evaluation, the transforms must be learned from the training set and not contain any knowledge from the testing set. A DataTransformProcess aids in this by providing a mechanism to conta
| 23 | * @author Edward Raff |
| 24 | */ |
| 25 | public class DataTransformProcess implements DataTransform, Parameterized |
| 26 | { |
| 27 | |
| 28 | private static final long serialVersionUID = -2844495690944305885L; |
| 29 | @ParameterHolder(skipSelfNamePrefix = true) |
| 30 | private List<DataTransform> transformSource; |
| 31 | private List<DataTransform> learnedTransforms; |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * Creates a new transform process that is empty. Transform factories must |
| 36 | * be added using |
| 37 | * {@link #addTransform(jsat.datatransform.DataTransformFactory) }. |
| 38 | */ |
| 39 | public DataTransformProcess() |
| 40 | { |
| 41 | transformSource = new ArrayList<DataTransform>(); |
| 42 | learnedTransforms = new ArrayList<DataTransform>(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates a new transform process from the listed factories, which will be |
| 47 | * applied in order by index. |
| 48 | * |
| 49 | * @param transforms the array of factories to apply as the data transform process |
| 50 | */ |
| 51 | public DataTransformProcess(DataTransform... transforms) |
| 52 | { |
| 53 | this(); |
| 54 | for(DataTransform dt : transforms) |
| 55 | this.addTransform(dt); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Adds a transform to the list of transforms. Transforms are learned and |
| 60 | * applied in the order in which they are added. |
| 61 | * @param transform the factory for the transform to add |
| 62 | */ |
| 63 | public void addTransform(DataTransform transform) |
| 64 | { |
| 65 | transformSource.add(transform); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * |
| 70 | * @return the number of transforms currently chained in this transform |
| 71 | * process |
| 72 | */ |
| 73 | public int getNumberOfTransforms() |
| 74 | { |
| 75 | return transformSource.size(); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Consolidates transformation objects when possible. Currently only works with {@link RemoveAttributeTransform} |
| 80 | */ |
| 81 | private void consolidateTransforms() |
| 82 | { |
nothing calls this directly
no outgoing calls
no test coverage detected