yzhao062 / pyod

A Python Library for Outlier and Anomaly Detection, Integrating Classical and Deep Learning Techniques
http://pyod.readthedocs.io
BSD 2-Clause "Simplified" License
8.43k stars 1.36k forks source link

ValueError when setting n_buckets parameter for function .aom #281

Open nrcjea001 opened 3 years ago

nrcjea001 commented 3 years ago

I'm getting a ValueError when setting n_buckets. The error states that n_buckets is not in range when it is in range:

combo: 0.1.2 pyod: 0.8.6

print(train_scores.shape)
(12115, 6)

outdf['if_out_scores'] = aom(train_scores, 2) # 2 groups

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-0efd40f1d59e> in <module>
     46 # del train_scores, x
     47 
---> 48 outdf['if_out_scores'] = aom(train_scores, 2) # 2 groups
     49 outdf['if_out_labels'] = aom(train_labels, 2)
     50 del adm, train_scores

~\Anaconda3\lib\site-packages\pyod\models\combination.py in aom(scores, n_buckets, method, bootstrap_estimators, random_state)
     52     """
     53 
---> 54     return combo_aom(scores, n_buckets, method, bootstrap_estimators,
     55                      random_state)
     56 

~\Anaconda3\lib\site-packages\combo\models\score_comb.py in aom(scores, n_buckets, method, bootstrap_estimators, random_state)
    167 
    168     """
--> 169     return _aom_moa_helper('AOM', scores, n_buckets, method,
    170                            bootstrap_estimators, random_state)
    171 

~\Anaconda3\lib\site-packages\combo\models\score_comb.py in _aom_moa_helper(mode, scores, n_buckets, method, bootstrap_estimators, random_state)
     69     # for now it is fixed at n_estimators/2
     70     n_estimators = scores.shape[1]
---> 71     check_parameter(n_buckets, 2, n_estimators, param_name='n_buckets')
     72 
     73     scores_buckets = np.zeros([scores.shape[0], n_buckets])

~\Anaconda3\lib\site-packages\pyod\utils\utility.py in check_parameter(param, low, high, param_name, include_left, include_right)
    102     elif (not include_left and not include_right) and (
    103             param <= low or param >= high):
--> 104         raise ValueError(
    105             '{param_name} is set to {param}. '
    106             'Not in the range of ({low}, {high}).'.format(

ValueError: n_buckets is set to 2. Not in the range of (2, 6).
yzhao062 commented 3 years ago

this is a valid point. I fixed the problem in combo https://github.com/yzhao062/combo/commit/5d3066ebf94be9012bc55f7e5e48fa3338bf2e60

will update back when 0.1.3. is published. or you could override the combo/models/score_comb.py line 71 as

check_parameter(n_buckets, 2, n_estimators, include_left=True, include_right=True, param_name='n_buckets')