Cosan  1.0
Data Analytics Library
Cosan::GridSearch< NumericType, Model, Metric, Split > Class Template Reference

#include <gridsearch.h>

Inheritance diagram for Cosan::GridSearch< NumericType, Model, Metric, Split >:
Cosan::Search Cosan::Selection Cosan::CosanBO

Public Member Functions

 GridSearch ()=delete
 
 GridSearch (CosanData< NumericType > &CRD, Model &estimator, Metric &metric, Split &split, const std::vector< NumericType > &paramGrid)
 
auto GetBestParams ()
 
- Public Member Functions inherited from Cosan::Selection
 Selection ()
 
- Public Member Functions inherited from Cosan::CosanBO
 CosanBO ()
 Default constructor. More...
 
virtual const std::string GetName () const
 Get the name of the objects. More...
 

Private Attributes

NumericType bestParam
 

Detailed Description

template<Numeric NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split>
class Cosan::GridSearch< NumericType, Model, Metric, Split >

Hyperparameter tuning for supervised models that have one or more hyperparameter(s) to tune Input required: estimator: class Model&, a model whose hyperparameters need to be tuned; metric: class Metric&, a metric to use in cross-validation split: Split & splitter method;* paramGrid: a vector of hyperparameters combination. For each entry of the vector, it corresponds to one choice of hyperparameter combination; Ouput: call .GetBestParams() to get the best hyperparameters combination. the choice of the hyper-parameter in paramGrid that forms the most accurate model

Definition at line 26 of file gridsearch.h.

Constructor & Destructor Documentation

◆ GridSearch() [1/2]

template<Numeric NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split>
Cosan::GridSearch< NumericType, Model, Metric, Split >::GridSearch ( )
delete

◆ GridSearch() [2/2]

template<Numeric NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split>
Cosan::GridSearch< NumericType, Model, Metric, Split >::GridSearch ( CosanData< NumericType > &  CRD,
Model &  estimator,
Metric &  metric,
Split &  split,
const std::vector< NumericType > &  paramGrid 
)
inline

Definition at line 29 of file gridsearch.h.

33  : Search() {
34  NumericType minError = std::numeric_limits<NumericType>::infinity();
35  NumericType currError;
36  decltype(bestParam) currParam;
37  for (gsl::index i = 0; i < paramGrid.size(); ++i){
38  currParam = paramGrid[i];
39  estimator.SetParams(paramGrid[i]);
40  currError = crossValidation(CRD, estimator, metric, split);
41  if (currError < minError)
42  {
43  minError = currError;
44  bestParam = currParam;
45  }
46  }
47  }

Member Function Documentation

◆ GetBestParams()

template<Numeric NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split>
auto Cosan::GridSearch< NumericType, Model, Metric, Split >::GetBestParams ( )
inline

Definition at line 48 of file gridsearch.h.

48 {return bestParam;}

Member Data Documentation

◆ bestParam

template<Numeric NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split>
NumericType Cosan::GridSearch< NumericType, Model, Metric, Split >::bestParam
private

Definition at line 51 of file gridsearch.h.


The documentation for this class was generated from the following file:
Cosan::GridSearch::bestParam
NumericType bestParam
Definition: gridsearch.h:51
NumericType
double NumericType
Definition: onehotencodingTest.cpp:20
Cosan::crossValidation
NumericType crossValidation(CosanData< NumericType > &CRD, Model &estimator, Metric &metric, Split &split)
Definition: crossvalidation.h:32
Cosan::Search::Search
Search()
Definition: selection.h:29