1
- from lenskit .algorithms import user_knn
2
- from ConfigSpace import Integer , Float
1
+ from lenskit .knn . user import UserKNNScorer , UserKNNConfig
2
+ from ConfigSpace import UniformIntegerHyperparameter , UniformFloatHyperparameter
3
3
from ConfigSpace import ConfigurationSpace
4
4
5
5
6
- class UserUser (user_knn .UserUser ):
7
- def __init__ (self , nnbrs , ** kwargs ):
8
- super ().__init__ (nnbrs = nnbrs , ** kwargs )
6
+ class UserUser (UserKNNScorer ):
7
+ def __init__ (self , max_nbrs , min_nbrs = 1 , min_sim = 1e-6 , ** kwargs ):
8
+ config = UserKNNConfig (
9
+ max_nbrs = max_nbrs ,
10
+ min_nbrs = min_nbrs ,
11
+ min_sim = min_sim ,
12
+ ** kwargs
13
+ )
14
+ super ().__init__ (config = config , ** kwargs )
9
15
10
16
@staticmethod
11
17
def get_default_configspace (** kwargs ):
12
18
"""
13
19
return default configuration spaces for hyperparameter
14
20
"""
15
21
"""
16
- The nnbrs hyperparameter is set to 10000 in LensKit-Auto. Generally speaking, the higher the nnbrs
22
+ The max_nbrs hyperparameter is set to 10000 in LensKit-Auto. Generally speaking, the higher the max_nbrs
17
23
hyperparameter value, the better the performance. But the computational cost will increase
18
- exponentially by increasing the nnbrs hyperparameter value. 10000 is a reasonable value for nnbrs
24
+ exponentially by increasing the max_nbrs hyperparameter value. 10000 is a reasonable value for max_nbrs
19
25
hyperparameter since it has relatively good performance and is still able
20
26
to run in a reasonable amount of time.
21
27
"""
22
- nnbrs = Integer ( 'nnbrs ' , bounds = ( 1 , 10000 ), default = 1000 , log = True ) # No default value given by LensKit
28
+ max_nbrs = UniformIntegerHyperparameter ( 'max_nbrs ' , lower = 1 , upper = 10000 , default_value = 1000 , log = True )
23
29
24
30
"""
25
- The min_sim hyperparameter describes the minimum number of neighbors for scoring each item.
31
+ The min_nbrs hyperparameter describes the minimum number of neighbors for scoring each item.
26
32
Since the LensKit default value for the min_nbrs hyperparameter is 1, we set the lower bound to 1.
27
- The upper bound is set to the nnbrs hyperparameter value.
33
+ The upper bound is set to the max_nbrs hyperparameter value.
28
34
Therefore, the upper bound of min_nbrs is set to 10000 to cover the full possible range of the
29
35
min_nbrs hyperparameter.
30
36
"""
31
- min_nbrs = Integer ('min_nbrs' , bounds = ( 1 , 1000 ), default = 1 , log = True )
37
+ min_nbrs = UniformIntegerHyperparameter ('min_nbrs' , lower = 1 , upper = 1000 , default_value = 1 , log = True )
32
38
33
39
"""
34
40
The min_sim hyperparameter describes the minimum threshold for similarity between items. It is commonly
@@ -44,9 +50,9 @@ def get_default_configspace(**kwargs):
44
50
Since the paper already states that it is very difficult to find the best value, we define a large bound around
45
51
the default LensKit value.
46
52
"""
47
- min_sim = Float ('min_sim' , bounds = ( 1.0e-10 , 1.0e-2 ), default = 1.0e-6 )
53
+ min_sim = UniformFloatHyperparameter ('min_sim' , lower = 1.0e-10 , upper = 1.0e-2 , default_value = 1.0e-6 , log = True )
48
54
49
55
cs = ConfigurationSpace ()
50
- cs .add_hyperparameters ([ min_nbrs , min_sim , nnbrs ])
56
+ cs .add ([ max_nbrs , min_nbrs , min_sim ])
51
57
52
58
return cs
0 commit comments