jsat.parameters
Class RandomSearch
- java.lang.Object
-
- jsat.parameters.ModelSearch
-
- jsat.parameters.RandomSearch
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Regressor
public class RandomSearch extends ModelSearch
Random Search is a simple method for tuning the parameters of a classification or regression algorithm. Each parameter is given a distribution that represents the values of interest, and trials are done by randomly sampling each parameter from their respective distributions. Compared toGridSearchthis method does better when lots of values are to be tested or when 2 or more parameters are to be evaluated.
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. See : Bergstra, J., & Bengio, Y. (2012). Random Search for Hyper-Parameter Optimization. Journal ofMachine Learning Research, 13, 281–305.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description RandomSearch(Classifier baseClassifier, int folds)Creates a new GridSearch to tune the specified parameters of a classification model.RandomSearch(RandomSearch toCopy)Copy constructorRandomSearch(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, Distribution dist)Adds a new double parameter to be altered for the model being tuned.voidaddParameter(IntParameter param, Distribution dist)Adds a new double parameter to be altered for the model being tuned.voidaddParameter(java.lang.String name, Distribution dist)Adds a new 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.
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.RandomSearchclone()intgetTrials()voidsetTrials(int trials)Sets the number of trials or samples that will be taken.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
-
RandomSearch
public RandomSearch(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 calling#addParameter(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
-
RandomSearch
public RandomSearch(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 calling#addParameter(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
-
RandomSearch
public RandomSearch(RandomSearch 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.
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
-
setTrials
public void setTrials(int trials)
Sets the number of trials or samples that will be taken. This value is the number of models that will be trained and evaluated for their performance- Parameters:
trials- the number of models to build and evaluate
-
getTrials
public int getTrials()
- Returns:
- the number of models that will be built to evaluate
-
addParameter
public void addParameter(DoubleParameter param, Distribution dist)
Adds a new double parameter to be altered for the model being tuned.- Parameters:
param- the model parameterinitialSearchValues- the distribution to sample from for this parameter
-
addParameter
public void addParameter(IntParameter param, Distribution dist)
Adds a new double parameter to be altered for the model being tuned.- Parameters:
param- the model parameterinitialSearchValues- the distribution to sample from for this parameter
-
addParameter
public void addParameter(java.lang.String name, Distribution dist)Adds a new 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(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.
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
clone
public RandomSearch clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Specified by:
clonein classModelSearch
-
-
DataMelt 3.0 © DataMelt by jWork.ORG