コード例 #1
0
    def __init__(self, base_algorithm, reward_estimator, nchoices, method='rovr',
                 handle_invalid=True, c=None, pmin=1e-5, beta_prior=None, smoothing=(1,2), **kwargs_costsens):
        assert (method == 'rovr') or (method == 'wap')
        self.method = method
        if method == 'wap':
            _check_constructor_input(base_algorithm, nchoices)
        else:
            assert isinstance(nchoices, int)
            assert nchoices > 2
            assert ('fit' in dir(base_algorithm)) and ('predict' in dir(base_algorithm))
        
        if c is not None:
            assert isinstance(c, float)
        if pmin is not None:
            assert isinstance(pmin, float)
        assert isinstance(handle_invalid, bool)
        
        if type(reward_estimator) == np.ndarray:
            assert reward_estimator.shape[1] == nchoices
            assert reward_estimator.shape[0] == X.shape[0]
        else:
            assert ('predict_proba_separate' in dir(reward_estimator)) or ('predict_proba' in dir(reward_estimator))

        if beta_prior is not None:
            beta_prior = _check_beta_prior(beta_prior, nchoices, 2)
        
        self.base_algorithm = base_algorithm
        self.reward_estimator = reward_estimator
        self.nchoices = nchoices
        self.c = c
        self.pmin = pmin
        self.handle_invalid = handle_invalid
        self.beta_prior = beta_prior
        self.smoothing = _check_smoothing(smoothing)
        self.kwargs_costsens = kwargs_costsens
コード例 #2
0
 def __init__(self, base_algorithm, nchoices, c=None, pmin=1e-5):
     _check_constructor_input(base_algorithm, nchoices)
     self.base_algorithm = base_algorithm
     self.nchoices = nchoices
     self.tree = _BinTree(nchoices)
     if c is not None:
         assert isinstance(c, float)
     if pmin is not None:
         assert isinstance(pmin, float)
     self.c = c
     self.pmin = pmin
コード例 #3
0
 def __init__(self, base_algorithm, nchoices, c = None, pmin = 1e-5, njobs = -1):
     try:
         from costsensitive import _BinTree
     except:
         raise ValueError("This functionality requires package 'costsensitive'.\nCan be installed with 'pip install costsensitive'.")
     _check_constructor_input(base_algorithm, nchoices)
     self.base_algorithm = base_algorithm
     self.nchoices = nchoices
     self.tree = _BinTree(nchoices)
     if c is not None:
         assert isinstance(c, float)
     if pmin is not None:
         assert isinstance(pmin, float)
     self.c = c
     self.pmin = pmin
     self.njobs = _check_njobs(njobs)