Class CrossValidationHelper


  • public class CrossValidationHelper
    extends Object
    Helper class for cross-validation.
    Version:
    $Revision$
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • PLACEHOLDER_ORIGINAL

        public static final String PLACEHOLDER_ORIGINAL
        the placeholder for the (original) relation name.
        See Also:
        Constant Field Values
      • PLACEHOLDER_TYPE

        public static final String PLACEHOLDER_TYPE
        the placeholder for "train" or "test" type.
        See Also:
        Constant Field Values
      • PLACEHOLDER_CURRENTFOLD

        public static final String PLACEHOLDER_CURRENTFOLD
        the placeholder for the current fold number.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CrossValidationHelper

        public CrossValidationHelper()
    • Method Detail

      • crossValidationIndices

        public static int[] crossValidationIndices​(weka.core.Instances data,
                                                   int folds,
                                                   Random random)
        Returns the indices from the original dataset for tracing the predictions back to the original dataset (stratified).
        Parameters:
        data - the original data
        folds - the number of folds
        random - the random number generator
        Returns:
        the indices
      • crossValidationIndices

        public static int[] crossValidationIndices​(weka.core.Instances data,
                                                   int folds,
                                                   Random random,
                                                   boolean stratify)
        Returns the indices from the original dataset for tracing the predictions back to the original dataset.
        Parameters:
        data - the original data
        folds - the number of folds
        random - the random number generator
        stratify - whether to stratify
        Returns:
        the indices
      • alignIndices

        public static int[] alignIndices​(int[] original)
        Reorders the indices to align with the original data.
        Parameters:
        original - the original indices
        Returns:
        the aligned data
      • alignPredictions

        public static ArrayList<weka.classifiers.evaluation.Prediction> alignPredictions​(ArrayList<weka.classifiers.evaluation.Prediction> predictions,
                                                                                         int[] original)
        Reorders the predictions to align with the original data.
        Parameters:
        predictions - the predictions to align
        original - the original indices
        Returns:
        the aligned data
      • createRelationName

        public static String createRelationName​(String relation,
                                                String template,
                                                int fold,
                                                boolean train)
        Generates a relation name for the current fold.
        Parameters:
        relation - the original relation name
        template - the template for the relation name
        fold - the current fold
        train - whether train or test set
        Returns:
        the relation name