jsat.parameters
Class ModelSearch
- java.lang.Object
-
- jsat.parameters.ModelSearch
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Regressor
- Direct Known Subclasses:
- GridSearch, RandomSearch
public abstract class ModelSearch extends java.lang.Object implements Classifier, Regressor
This abstract class provides boilerplate for algorithms that search a model's parameter space to find the parameters that provide the best overall performance.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ModelSearch(Classifier baseClassifier, int folds)ModelSearch(ModelSearch toCopy)Copy constructorModelSearch(Regressor baseRegressor, int folds)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.abstract ModelSearchclone()ClassifiergetBaseClassifier()Returns the base classifier that was originally passed in when constructing this GridSearch.RegressorgetBaseRegressor()Returns the base regressor that was originally passed in when constructing this GridSearch.ClassificationScoregetClassificationTargetScore()Returns the classification score that is trying to be optimized via grid searchRegressionScoregetRegressionTargetScore()Returns the regression score that is trying to be optimized via grid searchClassifiergetTrainedClassifier()Returns the resultant classifier trained on the whole data set after performing parameter tuning.RegressorgetTrainedRegressor()Returns the resultant regressor trained on the whole data set after performing parameter tuning.booleanisReuseSameCVFolds()booleanisTrainFinalModel()booleanisTrainModelsInParallel()doubleregress(DataPoint data)voidsetClassificationTargetScore(ClassificationScore classifierTargetScore)Sets the score to attempt to optimize when performing grid search on a classification problem.voidsetRegressionTargetScore(RegressionScore regressionTargetScore)Sets the score to attempt to optimize when performing grid search on a regression problem.voidsetReuseSameCVFolds(boolean reuseSameSplit)Sets whether or not one set of CV folds is created and re used for every parameter combination (the default), or if a difference set of CV folds will be used for every parameter combination.voidsetTrainFinalModel(boolean trainFinalModel)Iftrue(the default) the model that was found to be best is trained on the whole data set at the end.voidsetTrainModelsInParallel(boolean trainInParallel)When set totrue(the default) parallelism is obtained by training as many models in parallel as possible.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train, train
-
-
-
-
Constructor Detail
-
ModelSearch
public ModelSearch(Regressor baseRegressor, int folds)
-
ModelSearch
public ModelSearch(Classifier baseClassifier, int folds)
-
ModelSearch
public ModelSearch(ModelSearch toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setTrainModelsInParallel
public void setTrainModelsInParallel(boolean trainInParallel)
When set totrue(the default) parallelism is obtained by training as many models in parallel as possible. Iffalse, parallelsm will be obtained by training the model using theClassifier#train(jsat.classifiers.ClassificationDataSet, java.util.concurrent.ExecutorService)andRegressor#train(jsat.regression.RegressionDataSet, java.util.concurrent.ExecutorService)methods.
When a model supportswarms starts, parallelism obtained by training the models in parallel is intrinsically reduced, as a model can not be warms started until another model has finished. In the case that one of the parameters is annotated as awarm paramter, that parameter will be the one rained sequential, and for every other parameter combination models will be trained in parallel. If there is no warm parameter, the first parameter added will be used for warm training. If there is only one parameter and warm training is occurring, no parallelism will be obtained.- Parameters:
trainInParallel-trueto get parallelism from training many models at the same time,falseto get parallelism from getting the model's implicit parallelism.
-
isTrainModelsInParallel
public boolean isTrainModelsInParallel()
- Returns:
trueif parallelism is obtained from training many models at the same time,falseif parallelism is obtained from using the model's implicit parallelism.
-
setTrainFinalModel
public void setTrainFinalModel(boolean trainFinalModel)
Iftrue(the default) the model that was found to be best is trained on the whole data set at the end. Iffalse, the final model will not be trained. This means that this Object will not be usable for predictoin. This should only be set if you know you will not be using this model but only want to get the information about which parameter combination is best.- Parameters:
trainFinalModel-trueto train the final model after grid search,falseto not do that.
-
isTrainFinalModel
public boolean isTrainFinalModel()
- Returns:
trueto train the final model after grid search,falseto not do that.
-
setReuseSameCVFolds
public void setReuseSameCVFolds(boolean reuseSameSplit)
Sets whether or not one set of CV folds is created and re used for every parameter combination (the default), or if a difference set of CV folds will be used for every parameter combination.- Parameters:
reuseSameSplit-trueif the same split is re-used for every combination,falseif a new CV set is used for every parameter combination.
-
isReuseSameCVFolds
public boolean isReuseSameCVFolds()
- Returns:
trueif the same split is re-used for every combination,falseif a new CV set is used for every parameter combination.
-
getBaseClassifier
public Classifier getBaseClassifier()
Returns the base classifier that was originally passed in when constructing this GridSearch. If this was not constructed with a classifier, this may return null.- Returns:
- the original classifier object given
-
getTrainedClassifier
public Classifier getTrainedClassifier()
Returns the resultant classifier trained on the whole data set after performing parameter tuning.- Returns:
- the trained classifier after a call to
#train(jsat.regression.RegressionDataSet, java.util.concurrent.ExecutorService), or null if it has not been trained.
-
getBaseRegressor
public Regressor getBaseRegressor()
Returns the base regressor that was originally passed in when constructing this GridSearch. If this was not constructed with a regressor, this may return null.- Returns:
- the original regressor object given
-
getTrainedRegressor
public Regressor getTrainedRegressor()
Returns the resultant regressor trained on the whole data set after performing parameter tuning.- Returns:
- the trained regressor after a call to
#train(jsat.regression.RegressionDataSet, java.util.concurrent.ExecutorService), or null if it has not been trained.
-
setClassificationTargetScore
public void setClassificationTargetScore(ClassificationScore classifierTargetScore)
Sets the score to attempt to optimize when performing grid search on a classification problem.- Parameters:
classifierTargetScore- the score to optimize via grid search
-
getClassificationTargetScore
public ClassificationScore getClassificationTargetScore()
Returns the classification score that is trying to be optimized via grid search- Returns:
- the classification score that is trying to be optimized via grid search
-
setRegressionTargetScore
public void setRegressionTargetScore(RegressionScore regressionTargetScore)
Sets the score to attempt to optimize when performing grid search on a regression problem.- Parameters:
regressionTargetScore-
-
getRegressionTargetScore
public RegressionScore getRegressionTargetScore()
Returns the regression score that is trying to be optimized via grid search- Returns:
- the regression score that is trying to be optimized via grid search
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClassifier- Specified by:
supportsWeightedDatain interfaceRegressor- Returns:
- true if the model supports weighted data, false otherwise
-
clone
public abstract ModelSearch clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG