Click or drag to resize
Accord.NET (logo)

BootstrapTModel, TInput Class

Bootstrap method for generalization performance measurements (with support for stratification and default loss function for classification).
Inheritance Hierarchy
SystemObject
  Accord.MachineLearningParallelLearningBase
    Accord.MachineLearning.PerformanceBaseSplitSetValidationBootstrapResultTModel, TInput, Int32, TModel, ISupervisedLearningTModel, TInput, Int32, TInput, Int32
      Accord.MachineLearning.PerformanceBaseSplitSetValidationBootstrapResultTModel, TInput, Int32, TModel, TInput, Int32
        Accord.MachineLearning.PerformanceBootstrapTModel, TInput, Int32
          Accord.MachineLearning.PerformanceBootstrapTModel, TInput

Namespace:  Accord.MachineLearning.Performance
Assembly:  Accord.MachineLearning (in Accord.MachineLearning.dll) Version: 3.8.0
Syntax
public class Bootstrap<TModel, TInput> : Bootstrap<TModel, TInput, int>
where TModel : class, Object, IClassifier<TInput, int>
Request Example View Source

Type Parameters

TModel
The type of the machine learning model.
TInput
The type of the input data.

The BootstrapTModel, TInput type exposes the following members.

Constructors
  NameDescription
Public methodBootstrapTModel, TInput
Initializes a new instance of the BootstrapTModel, TInput class.
Top
Properties
  NameDescription
Public propertyB
Gets or sets the number B of bootstrap samplings to be drawn from the population dataset.
(Inherited from BootstrapTModel, TInput, TOutput.)
Public propertyDefaultValue
Gets or sets a value to be used as the Loss in case the model throws an exception during learning. Default is null (exceptions will not be ignored).
(Inherited from BaseSplitSetValidationTResult, TModel, TLearner, TInput, TOutput.)
Public propertyFit (Inherited from BaseSplitSetValidationTResult, TModel, TLearner, TInput, TOutput.)
Public propertyLearner (Inherited from BaseSplitSetValidationTResult, TModel, TLearner, TInput, TOutput.)
Public propertyLoss
Gets or sets a ComputeLossTOutput, TInfo function that can be used to measure how far the actual model predictions were from the expected ground-truth.
(Inherited from BaseSplitSetValidationTResult, TModel, TLearner, TInput, TOutput.)
Public propertyNumberOfSubsamples
Gets or sets the number of samples to be drawn in each subsample. If set to zero, all samples in the entire dataset will be selected.
(Inherited from BootstrapTModel, TInput, TOutput.)
Public propertyParallelOptions
Gets or sets the parallelization options for this algorithm.
(Inherited from ParallelLearningBase.)
Public propertyStratify
Gets or sets a value indicating whether the prevalence of an output label should be balanced between training and testing sets. Default is false.
Public propertySubSampleIndices
Gets the bootstrap samples drawn from the population dataset as indices.
(Inherited from BootstrapTModel, TInput, TOutput.)
Public propertyToken
Gets or sets a cancellation token that can be used to cancel the algorithm while it is running.
(Inherited from ParallelLearningBase.)
Top
Methods
  NameDescription
Protected methodCreateSubSampleIndices
Draws the bootstrap samples from the population.
(Overrides BootstrapTModel, TInput, TOutputCreateSubSampleIndices(TInput, TOutput, Int32, Int32).)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetSubsample
Gets a subset of the training and testing sets.
(Inherited from BootstrapTModel, TInput, TOutput.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodLearn
Learns a model that can map the given inputs to the given outputs.
(Inherited from BootstrapTModel, TInput, TOutput.)
Protected methodLearnSubset
Learns and evaluates a model in a single subset of the data.
(Inherited from BaseSplitSetValidationTResult, TModel, TLearner, TInput, TOutput.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Examples
// Ensure results are reproducible
Accord.Math.Random.Generator.Seed = 0;

// This is a sample code on how to use Cross-Validation
// to assess the performance of Support Vector Machines.

// Consider the example binary data. We will be trying
// to learn a XOR problem and see how well does SVMs
// perform on this data.

double[][] data =
{
    new double[] { -1, -1 }, new double[] {  1, -1 },
    new double[] { -1,  1 }, new double[] {  1,  1 },
    new double[] { -1, -1 }, new double[] {  1, -1 },
    new double[] { -1,  1 }, new double[] {  1,  1 },
    new double[] { -1, -1 }, new double[] {  1, -1 },
    new double[] { -1,  1 }, new double[] {  1,  1 },
    new double[] { -1, -1 }, new double[] {  1, -1 },
    new double[] { -1,  1 }, new double[] {  1,  1 },
};

int[] xor = // result of xor for the sample input data
{
    -1,       1,
     1,      -1,
    -1,       1,
     1,      -1,
    -1,       1,
     1,      -1,
    -1,       1,
     1,      -1,
};


// Create a new Bootstrap algorithm passing the data set size and the number of folds
var bootstrap = new Bootstrap<SupportVectorMachine<Linear, double[]>, double[]>()
{
    B = 1000, // Use 1000 resamplings when doing bootstrap

    Learner = (s) => new SequentialMinimalOptimization<Linear, double[]>()
    {
        Complexity = 100
    },

    Loss = (expected, actual, p) => new ZeroOneLoss(expected).Loss(actual),

    Stratify = false, // do not use stratification

    DefaultValue = 1.0, // value to use as error if the algorithm throws an exception
};

bootstrap.ParallelOptions.MaxDegreeOfParallelism = 1;

// Compute the bootstrap
var result = bootstrap.Learn(data, xor);

// Finally, access the measured performance.
double trainingErrors = result.Training.Mean;
double validationErrors = result.Validation.Mean;
double estimate632  = result.Estimate;
See Also