jsat.parameters
Class GridSearch
- java.lang.Object
-
- jsat.parameters.ModelSearch
-
- jsat.parameters.GridSearch
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Regressor
public class GridSearch extends ModelSearch
GridSearch is a simple method for tuning the parameters of a classification or regression algorithm. It naively tries all possible pairs of parameter values given. For this reason, it works best when only a small number of parameters need to be turned.
The model it takes must implement theParameterizedinterface. By default, no parameters are selected for optimizations. This is because parameters value ranges are often algorithm specific. As such, the user must specify the parameters and the values to test using the addParameter methods.
-
-
Constructor Summary
Constructors Constructor and Description GridSearch(Classifier baseClassifier, int folds)Creates a new GridSearch to tune the specified parameters of a classification model.GridSearch(GridSearch toCopy)Copy constructorGridSearch(Regressor baseRegressor, int folds)Creates a new GridSearch to tune the specified parameters of a regression model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddParameter(DoubleParameter param, double... initialSearchValues)Adds a new double parameter to be altered for the model being tuned.voidaddParameter(IntParameter param, int... initialSearchValues)Adds a new int parameter to be altered for the model being tuned.voidaddParameter(java.lang.String name, double... initialSearchValues)Adds a new double parameter to be altered for the model being tuned.voidaddParameter(java.lang.String name, int... initialSearchValues)Adds a new integer parameter to be altered for the model being tuned.intautoAddParameters(DataSet data)This method will automatically populate the search space with parameters based on which Parameter objects return non-null distributions.intautoAddParameters(DataSet data, int paramsEach)This method will automatically populate the search space with parameters based on which Parameter objects return non-null distributions.
Note, using this method with Cross Validation has the potential for over-estimating the accuracy of results if the data set is actually used to for parameter guessing.GridSearchclone()booleanisUseWarmStarts()voidsetUseWarmStarts(boolean useWarmStarts)Sets whether or not warm starts are used, but only if the model in use supports warm starts.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet dataSet, boolean parallel)-
Methods inherited from class jsat.parameters.ModelSearch
classify, getBaseClassifier, getBaseRegressor, getClassificationTargetScore, getRegressionTargetScore, getTrainedClassifier, getTrainedRegressor, isReuseSameCVFolds, isTrainFinalModel, isTrainModelsInParallel, regress, setClassificationTargetScore, setRegressionTargetScore, setReuseSameCVFolds, setTrainFinalModel, setTrainModelsInParallel, supportsWeightedData
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
-
-
-
Constructor Detail
-
GridSearch
public GridSearch(Regressor baseRegressor, int folds)
Creates a new GridSearch to tune the specified parameters of a regression model. The parameters still need to be specified by callingaddParameter(jsat.parameters.DoubleParameter, double[])- Parameters:
baseRegressor- the regressor to tune the parameters offolds- the number of folds of cross-validation to perform to evaluate each combination of parameters- Throws:
FailedToFitException- if the base regressor does not implementParameterized
-
GridSearch
public GridSearch(Classifier baseClassifier, int folds)
Creates a new GridSearch to tune the specified parameters of a classification model. The parameters still need to be specified by callingaddParameter(jsat.parameters.DoubleParameter, double[])- Parameters:
baseClassifier- the classifier to tune the parameters offolds- the number of folds of cross-validation to perform to evaluate each combination of parameters- Throws:
FailedToFitException- if the base classifier does not implementParameterized
-
GridSearch
public GridSearch(GridSearch toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
autoAddParameters
public int autoAddParameters(DataSet data)
This method will automatically populate the search space with parameters based on which Parameter objects return non-null distributions. Each parameter will be tested with 10 different values
Note, using this method with Cross Validation has the potential for over-estimating the accuracy of results if the data set is actually used to for parameter guessing.
It is possible for this method to return 0, indicating that no default parameters could be found. The intended interpretation is that there are no parameters that you need to tune to get good performance from the given model. Though there will be cases where the author has simply missed a class.- Parameters:
data- the data set to get parameter estimates from- Returns:
- the number of parameters added
-
autoAddParameters
public int autoAddParameters(DataSet data, int paramsEach)
This method will automatically populate the search space with parameters based on which Parameter objects return non-null distributions.
Note, using this method with Cross Validation has the potential for over-estimating the accuracy of results if the data set is actually used to for parameter guessing.- Parameters:
data- the data set to get parameter estimates fromparamsEach- the number of parameters value to try for each parameter found- Returns:
- the number of parameters added
-
setUseWarmStarts
public void setUseWarmStarts(boolean useWarmStarts)
Sets whether or not warm starts are used, but only if the model in use supports warm starts. This is set totrueby default.- Parameters:
useWarmStarts-trueif warm starts should be used when possible,falseotherwise.
-
isUseWarmStarts
public boolean isUseWarmStarts()
- Returns:
trueif warm starts will be used when possible.falseif they will not.
-
addParameter
public void addParameter(DoubleParameter param, double... initialSearchValues)
Adds a new double parameter to be altered for the model being tuned.- Parameters:
param- the model parameterinitialSearchValues- the values to try for the specified parameter
-
addParameter
public void addParameter(java.lang.String name, double... initialSearchValues)Adds a new double parameter to be altered for the model being tuned.- Parameters:
name- the name of the parameterinitialSearchValues- the values to try for the specified parameter
-
addParameter
public void addParameter(IntParameter param, int... initialSearchValues)
Adds a new int parameter to be altered for the model being tuned.- Parameters:
param- the model parameterinitialSearchValues- the values to try for the specified parameter
-
addParameter
public void addParameter(java.lang.String name, int... initialSearchValues)Adds a new integer parameter to be altered for the model being tuned.- Parameters:
name- the name of the parameterinitialSearchValues- the values to try for the specified parameter
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
train
public void train(ClassificationDataSet dataSet, boolean parallel)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
clone
public GridSearch clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Specified by:
clonein classModelSearch
-
-
DataMelt 3.0 © DataMelt by jWork.ORG