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