GridSearchTModel Class |
Note: This API is now obsolete.
Namespace: Accord.MachineLearning
[SerializableAttribute] [ObsoleteAttribute("Please use GridSearch<TModel, TInput, TOutput> instead.")] public class GridSearch<TModel> : IParallel, ISupportsCancellation where TModel : class
The GridSearchTModel type exposes the following members.
Name | Description | |
---|---|---|
GridSearchTModel |
Constructs a new Grid search algorithm.
|
Name | Description | |
---|---|---|
Fitting |
A function that fits a model using the given parameters.
| |
ParallelOptions |
Gets or sets the parallelization options for this algorithm.
| |
ParameterRanges |
The range of parameters to consider during search.
| |
Token |
Gets or sets a cancellation token that can be used
to cancel the algorithm while it is running.
|
Name | Description | |
---|---|---|
Compute |
Searches for the best combination of parameters that results in the most accurate model.
| |
Compute(GridSearchParameterCollection, Double) |
Searches for the best combination of parameters that results in the most accurate model.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(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.) | |
ToT | 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.) |
// Example binary data double[][] inputs = { new double[] { -1, -1 }, new double[] { -1, 1 }, new double[] { 1, -1 }, new double[] { 1, 1 } }; int[] xor = // xor labels { -1, 1, 1, -1 }; // Declare the parameters and ranges to be searched GridSearchRange[] ranges = { new GridSearchRange("complexity", new double[] { 0.00000001, 5.20, 0.30, 0.50 } ), new GridSearchRange("degree", new double[] { 1, 10, 2, 3, 4, 5 } ), new GridSearchRange("constant", new double[] { 0, 1, 2 } ) }; // Instantiate a new Grid Search algorithm for Kernel Support Vector Machines var gridsearch = new GridSearch<KernelSupportVectorMachine>(ranges); // Set the fitting function for the algorithm gridsearch.Fitting = delegate(GridSearchParameterCollection parameters, out double error) { // The parameters to be tried will be passed as a function parameter. int degree = (int)parameters["degree"].Value; double constant = parameters["constant"].Value; double complexity = parameters["complexity"].Value; // Use the parameters to build the SVM model Polynomial kernel = new Polynomial(degree, constant); KernelSupportVectorMachine ksvm = new KernelSupportVectorMachine(kernel, 2); // Create a new learning algorithm for SVMs SequentialMinimalOptimization smo = new SequentialMinimalOptimization(ksvm, inputs, xor); smo.Complexity = complexity; // Measure the model performance to return as an out parameter error = smo.Run(); return ksvm; // Return the current model }; // Declare some out variables to pass to the grid search algorithm GridSearchParameterCollection bestParameters; double minError; // Compute the grid search to find the best Support Vector Machine KernelSupportVectorMachine bestModel = gridsearch.Compute(out bestParameters, out minError);