src.fairreckitlib.model.algorithms.surprise.surprise_params

This module contains the parameter creation functions for surprise predictors/recommenders.

Functions:

add_baseline_als_params_to: add baseline config parameters that use ALS.
add_baseline_sgd_params_to: add baseline config parameters that use SGD.
create_params_baseline_only_als: create BaselineOnly config parameters with ALS.
create_params_baseline_only_sgd: create BaselineOnly config parameters with SGD.
create_params_co_clustering: create CoClustering config parameters.
create_params_knn: create KNN base config parameters.
create_params_knn_baseline: create KNNBaseline base config parameters.
create_params_knn_baseline_als: create KNNBaseline config parameters with ALS.
create_params_knn_baseline_sgd: create KNNBaseline config parameters with SGD.
create_params_knn_similarities: create KNN config parameters with similarities.
create_params_nmf: create NMF config parameters.
create_params_svd: create SVD config parameters.
create_params_svd_pp: create SVDpp config parameters.

This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)

  1"""This module contains the parameter creation functions for surprise predictors/recommenders.
  2
  3Functions:
  4
  5    add_baseline_als_params_to: add baseline config parameters that use ALS.
  6    add_baseline_sgd_params_to: add baseline config parameters that use SGD.
  7    create_params_baseline_only_als: create BaselineOnly config parameters with ALS.
  8    create_params_baseline_only_sgd: create BaselineOnly config parameters with SGD.
  9    create_params_co_clustering: create CoClustering config parameters.
 10    create_params_knn: create KNN base config parameters.
 11    create_params_knn_baseline: create KNNBaseline base config parameters.
 12    create_params_knn_baseline_als: create KNNBaseline config parameters with ALS.
 13    create_params_knn_baseline_sgd: create KNNBaseline config parameters with SGD.
 14    create_params_knn_similarities: create KNN config parameters with similarities.
 15    create_params_nmf: create NMF config parameters.
 16    create_params_svd: create SVD config parameters.
 17    create_params_svd_pp: create SVDpp config parameters.
 18
 19This program has been developed by students from the bachelor Computer Science at
 20Utrecht University within the Software Project course.
 21© Copyright Utrecht University (Department of Information and Computing Sciences)
 22"""
 23
 24from ....core.config.config_parameters import ConfigParameters
 25
 26
 27def add_baseline_als_params_to(params: ConfigParameters) -> ConfigParameters:
 28    """Add the parameters of the Baseline options with ALS.
 29
 30    Args:
 31        params: the parameters to add the baseline options to.
 32
 33    Returns:
 34        the configuration parameters of the algorithm.
 35    """
 36    params.add_number('epochs', int, 10, (1, 50))
 37    params.add_number('reg_i', int, 10, (1, 100))
 38    params.add_number('reg_u', int, 15, (1, 100))
 39    return params
 40
 41
 42def add_baseline_sgd_params_to(params: ConfigParameters) -> ConfigParameters:
 43    """Add the parameters of the Baseline options with SGD.
 44
 45    Args:
 46        params: the parameters to add the baseline options to.
 47
 48    Returns:
 49        the configuration parameters of the algorithm.
 50    """
 51    params.add_number('epochs', int, 20, (1, 50))
 52    params.add_number('regularization', float, 0.02, (0.00001, 1.0))
 53    params.add_number('learning_rate', float, 0.005, (0.0001, 1.0))
 54    return params
 55
 56
 57def create_params_baseline_only_als() -> ConfigParameters:
 58    """Create the parameters of the BaselineOnly ALS algorithm.
 59
 60    Returns:
 61        the configuration parameters of the algorithm.
 62    """
 63    return add_baseline_als_params_to(ConfigParameters())
 64
 65
 66def create_params_baseline_only_sgd() -> ConfigParameters:
 67    """Create the parameters of the BaselineOnly SGD algorithm.
 68
 69    Returns:
 70        the configuration parameters of the algorithm.
 71    """
 72    return add_baseline_sgd_params_to(ConfigParameters())
 73
 74
 75def create_params_co_clustering() -> ConfigParameters:
 76    """Create the parameters of the CoClustering algorithm.
 77
 78    Returns:
 79        the configuration parameters of the algorithm.
 80    """
 81    params = ConfigParameters()
 82    params.add_number('epochs', int, 20, (1, 50))
 83    params.add_number('user_clusters', int, 3, (0, 30))
 84    params.add_number('item_clusters', int, 3, (0, 30))
 85    params.add_random_seed('random_seed')
 86    return params
 87
 88
 89def create_params_knn() -> ConfigParameters:
 90    """Create the base parameters of all KNN algorithms.
 91
 92    Returns:
 93        the configuration parameters of the algorithm.
 94    """
 95    params = ConfigParameters()
 96    params.add_number('max_k', int, 40, (1, 100))
 97    params.add_number('min_k', int, 1, (1, 100))
 98    params.add_bool('user_based', True)
 99    params.add_number('min_support', int, 1, (1, 100))
100    return params
101
102
103def create_params_knn_baseline() -> ConfigParameters:
104    """Create the base parameters of both KNN Baseline algorithms.
105
106    Returns:
107        the configuration parameters of the algorithm.
108    """
109    params = create_params_knn()
110    params.add_number('shrinkage', int, 100, (1, 1000))
111    return params
112
113
114def create_params_knn_baseline_als() -> ConfigParameters:
115    """Create the parameters of the KNN Baseline algorithm with ALS.
116
117    Returns:
118        the configuration parameters of the algorithm.
119    """
120    params = create_params_knn_baseline()
121    return add_baseline_als_params_to(params)
122
123
124def create_params_knn_baseline_sgd() -> ConfigParameters:
125    """Create the parameters of the KNN Baseline algorithm with SGD.
126
127    Returns:
128        the configuration parameters of the algorithm.
129    """
130    params = create_params_knn_baseline()
131    return add_baseline_sgd_params_to(params)
132
133
134def create_params_knn_similarities() -> ConfigParameters:
135    """Create the parameters of the KNN algorithm with similarities.
136
137    Returns:
138        the configuration parameters of the algorithm.
139    """
140    similarities = ['MSD', 'cosine', 'pearson']
141
142    params = create_params_knn()
143    params.add_single_option('similarity', str, similarities[0], similarities)
144    return params
145
146
147def create_params_nmf() -> ConfigParameters:
148    """Create the parameters of the NMF algorithm.
149
150    Returns:
151        the configuration parameters of the algorithm.
152    """
153    params = ConfigParameters()
154    params.add_number('factors', int, 15, (1, 100))
155    params.add_number('epochs', int, 50, (1, 50))
156    params.add_number('reg_pu', float, 0.06, (0.00001, 1.0))
157    params.add_number('reg_qi', float, 0.06, (0.00001, 1.0))
158    params.add_number('init_low', int, 0, (0, 100))
159    params.add_number('init_high', int, 1, (0, 100))
160    params.add_random_seed('random_seed')
161    return params
162
163
164def create_params_svd() -> ConfigParameters:
165    """Create the parameters of the SVD algorithm.
166
167    Returns:
168        the configuration parameters of the algorithm.
169    """
170    params = ConfigParameters()
171    params.add_number('factors', int, 100, (1, 100))
172    params.add_number('epochs', int, 20, (1, 50))
173    params.add_number('init_mean', int, 0, (-1000, 1000))
174    params.add_number('init_std_dev', float, 0.1, (0.0, 1.0))
175    params.add_number('learning_rate', float, 0.005, (0.00001, 1.0))
176    params.add_number('regularization', float, 0.02, (0.00001, 1.0))
177    params.add_random_seed('random_seed')
178    params.add_bool('biased', True)
179    return params
180
181
182def create_params_svd_pp() -> ConfigParameters:
183    """Create the parameters of the SVDpp algorithm.
184
185    Returns:
186        the configuration parameters of the algorithm.
187    """
188    params = ConfigParameters()
189    params.add_number('factors', int, 20, (1, 100))
190    params.add_number('epochs', int, 20, (1, 50))
191    params.add_number('init_mean', int, 0, (-1000, 1000))
192    params.add_number('init_std_dev', float, 0.1, (0.0, 1.0))
193    params.add_number('learning_rate', float, 0.007, (0.00001, 1.0))
194    params.add_number('regularization', float, 0.02, (0.00001, 1.0))
195    params.add_random_seed('random_seed')
196    return params
def add_baseline_als_params_to( params: src.fairreckitlib.core.config.config_parameters.ConfigParameters) -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
28def add_baseline_als_params_to(params: ConfigParameters) -> ConfigParameters:
29    """Add the parameters of the Baseline options with ALS.
30
31    Args:
32        params: the parameters to add the baseline options to.
33
34    Returns:
35        the configuration parameters of the algorithm.
36    """
37    params.add_number('epochs', int, 10, (1, 50))
38    params.add_number('reg_i', int, 10, (1, 100))
39    params.add_number('reg_u', int, 15, (1, 100))
40    return params

Add the parameters of the Baseline options with ALS.

Args: params: the parameters to add the baseline options to.

Returns: the configuration parameters of the algorithm.

def add_baseline_sgd_params_to( params: src.fairreckitlib.core.config.config_parameters.ConfigParameters) -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
43def add_baseline_sgd_params_to(params: ConfigParameters) -> ConfigParameters:
44    """Add the parameters of the Baseline options with SGD.
45
46    Args:
47        params: the parameters to add the baseline options to.
48
49    Returns:
50        the configuration parameters of the algorithm.
51    """
52    params.add_number('epochs', int, 20, (1, 50))
53    params.add_number('regularization', float, 0.02, (0.00001, 1.0))
54    params.add_number('learning_rate', float, 0.005, (0.0001, 1.0))
55    return params

Add the parameters of the Baseline options with SGD.

Args: params: the parameters to add the baseline options to.

Returns: the configuration parameters of the algorithm.

def create_params_baseline_only_als() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
58def create_params_baseline_only_als() -> ConfigParameters:
59    """Create the parameters of the BaselineOnly ALS algorithm.
60
61    Returns:
62        the configuration parameters of the algorithm.
63    """
64    return add_baseline_als_params_to(ConfigParameters())

Create the parameters of the BaselineOnly ALS algorithm.

Returns: the configuration parameters of the algorithm.

def create_params_baseline_only_sgd() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
67def create_params_baseline_only_sgd() -> ConfigParameters:
68    """Create the parameters of the BaselineOnly SGD algorithm.
69
70    Returns:
71        the configuration parameters of the algorithm.
72    """
73    return add_baseline_sgd_params_to(ConfigParameters())

Create the parameters of the BaselineOnly SGD algorithm.

Returns: the configuration parameters of the algorithm.

def create_params_co_clustering() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
76def create_params_co_clustering() -> ConfigParameters:
77    """Create the parameters of the CoClustering algorithm.
78
79    Returns:
80        the configuration parameters of the algorithm.
81    """
82    params = ConfigParameters()
83    params.add_number('epochs', int, 20, (1, 50))
84    params.add_number('user_clusters', int, 3, (0, 30))
85    params.add_number('item_clusters', int, 3, (0, 30))
86    params.add_random_seed('random_seed')
87    return params

Create the parameters of the CoClustering algorithm.

Returns: the configuration parameters of the algorithm.

def create_params_knn() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
 90def create_params_knn() -> ConfigParameters:
 91    """Create the base parameters of all KNN algorithms.
 92
 93    Returns:
 94        the configuration parameters of the algorithm.
 95    """
 96    params = ConfigParameters()
 97    params.add_number('max_k', int, 40, (1, 100))
 98    params.add_number('min_k', int, 1, (1, 100))
 99    params.add_bool('user_based', True)
100    params.add_number('min_support', int, 1, (1, 100))
101    return params

Create the base parameters of all KNN algorithms.

Returns: the configuration parameters of the algorithm.

def create_params_knn_baseline() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
104def create_params_knn_baseline() -> ConfigParameters:
105    """Create the base parameters of both KNN Baseline algorithms.
106
107    Returns:
108        the configuration parameters of the algorithm.
109    """
110    params = create_params_knn()
111    params.add_number('shrinkage', int, 100, (1, 1000))
112    return params

Create the base parameters of both KNN Baseline algorithms.

Returns: the configuration parameters of the algorithm.

def create_params_knn_baseline_als() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
115def create_params_knn_baseline_als() -> ConfigParameters:
116    """Create the parameters of the KNN Baseline algorithm with ALS.
117
118    Returns:
119        the configuration parameters of the algorithm.
120    """
121    params = create_params_knn_baseline()
122    return add_baseline_als_params_to(params)

Create the parameters of the KNN Baseline algorithm with ALS.

Returns: the configuration parameters of the algorithm.

def create_params_knn_baseline_sgd() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
125def create_params_knn_baseline_sgd() -> ConfigParameters:
126    """Create the parameters of the KNN Baseline algorithm with SGD.
127
128    Returns:
129        the configuration parameters of the algorithm.
130    """
131    params = create_params_knn_baseline()
132    return add_baseline_sgd_params_to(params)

Create the parameters of the KNN Baseline algorithm with SGD.

Returns: the configuration parameters of the algorithm.

def create_params_knn_similarities() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
135def create_params_knn_similarities() -> ConfigParameters:
136    """Create the parameters of the KNN algorithm with similarities.
137
138    Returns:
139        the configuration parameters of the algorithm.
140    """
141    similarities = ['MSD', 'cosine', 'pearson']
142
143    params = create_params_knn()
144    params.add_single_option('similarity', str, similarities[0], similarities)
145    return params

Create the parameters of the KNN algorithm with similarities.

Returns: the configuration parameters of the algorithm.

def create_params_nmf() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
148def create_params_nmf() -> ConfigParameters:
149    """Create the parameters of the NMF algorithm.
150
151    Returns:
152        the configuration parameters of the algorithm.
153    """
154    params = ConfigParameters()
155    params.add_number('factors', int, 15, (1, 100))
156    params.add_number('epochs', int, 50, (1, 50))
157    params.add_number('reg_pu', float, 0.06, (0.00001, 1.0))
158    params.add_number('reg_qi', float, 0.06, (0.00001, 1.0))
159    params.add_number('init_low', int, 0, (0, 100))
160    params.add_number('init_high', int, 1, (0, 100))
161    params.add_random_seed('random_seed')
162    return params

Create the parameters of the NMF algorithm.

Returns: the configuration parameters of the algorithm.

def create_params_svd() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
165def create_params_svd() -> ConfigParameters:
166    """Create the parameters of the SVD algorithm.
167
168    Returns:
169        the configuration parameters of the algorithm.
170    """
171    params = ConfigParameters()
172    params.add_number('factors', int, 100, (1, 100))
173    params.add_number('epochs', int, 20, (1, 50))
174    params.add_number('init_mean', int, 0, (-1000, 1000))
175    params.add_number('init_std_dev', float, 0.1, (0.0, 1.0))
176    params.add_number('learning_rate', float, 0.005, (0.00001, 1.0))
177    params.add_number('regularization', float, 0.02, (0.00001, 1.0))
178    params.add_random_seed('random_seed')
179    params.add_bool('biased', True)
180    return params

Create the parameters of the SVD algorithm.

Returns: the configuration parameters of the algorithm.

def create_params_svd_pp() -> src.fairreckitlib.core.config.config_parameters.ConfigParameters:
183def create_params_svd_pp() -> ConfigParameters:
184    """Create the parameters of the SVDpp algorithm.
185
186    Returns:
187        the configuration parameters of the algorithm.
188    """
189    params = ConfigParameters()
190    params.add_number('factors', int, 20, (1, 100))
191    params.add_number('epochs', int, 20, (1, 50))
192    params.add_number('init_mean', int, 0, (-1000, 1000))
193    params.add_number('init_std_dev', float, 0.1, (0.0, 1.0))
194    params.add_number('learning_rate', float, 0.007, (0.00001, 1.0))
195    params.add_number('regularization', float, 0.02, (0.00001, 1.0))
196    params.add_random_seed('random_seed')
197    return params

Create the parameters of the SVDpp algorithm.

Returns: the configuration parameters of the algorithm.