Commit 7560608ff0ed29a55e057f4d76bfc9c86ea1d2cc
1 parent
d5b8b1c7
Exists in
master
and in
1 other branch
Added strategies tuning parameters to set_strategy method.
Showing
1 changed file
with
22 additions
and
16 deletions
Show diff stats
src/recommender.py
... | ... | @@ -104,10 +104,18 @@ class Recommender: |
104 | 104 | self.weight = xapian.TradWeight() |
105 | 105 | self.set_strategy(cfg.strategy) |
106 | 106 | |
107 | - def set_strategy(self,strategy_str): | |
107 | + def set_strategy(self,strategy_str,k=0,n=0): | |
108 | 108 | """ |
109 | 109 | Set the recommendation strategy. |
110 | 110 | """ |
111 | + if k: | |
112 | + k_neighbors = k | |
113 | + else: | |
114 | + k_neighbors = self.cfg.k_neighbors | |
115 | + if n: | |
116 | + profile_size = n | |
117 | + else: | |
118 | + profile_size = self.cfg.profile_size | |
111 | 119 | logging.info("Setting recommender strategy to \'%s\'" % strategy_str) |
112 | 120 | # Check if collaborative strategies can be instanciated |
113 | 121 | if "knn" in strategy_str: |
... | ... | @@ -126,33 +134,31 @@ class Recommender: |
126 | 134 | # self.users_repository = self.popcon_programs |
127 | 135 | # Set strategy based on strategy_str |
128 | 136 | if strategy_str == "cb": |
129 | - self.strategy = strategy.ContentBased("mix",self.cfg.profile_size) | |
137 | + self.strategy = strategy.ContentBased("mix",profile_size) | |
130 | 138 | elif strategy_str == "cbt": |
131 | - self.strategy = strategy.ContentBased("tag",self.cfg.profile_size) | |
139 | + self.strategy = strategy.ContentBased("tag",profile_size) | |
132 | 140 | elif strategy_str == "cbd": |
133 | - self.strategy = strategy.ContentBased("desc",self.cfg.profile_size) | |
141 | + self.strategy = strategy.ContentBased("desc",profile_size) | |
134 | 142 | elif strategy_str == "cbh": |
135 | - self.strategy = strategy.ContentBased("half",self.cfg.profile_size) | |
143 | + self.strategy = strategy.ContentBased("half",profile_size) | |
136 | 144 | if strategy_str == "cb_eset": |
137 | - self.strategy = strategy.ContentBased("mix_eset",self.cfg.profile_size) | |
145 | + self.strategy = strategy.ContentBased("mix_eset",profile_size) | |
138 | 146 | elif strategy_str == "cbt_eset": |
139 | - self.strategy = strategy.ContentBased("tag_eset",self.cfg.profile_size) | |
147 | + self.strategy = strategy.ContentBased("tag_eset",profile_size) | |
140 | 148 | elif strategy_str == "cbd_eset": |
141 | - self.strategy = strategy.ContentBased("desc_eset",self.cfg.profile_size) | |
149 | + self.strategy = strategy.ContentBased("desc_eset",profile_size) | |
142 | 150 | elif strategy_str == "cbh_eset": |
143 | - self.strategy = strategy.ContentBased("half_eset",self.cfg.profile_size) | |
144 | - #elif strategy_str == "col": | |
145 | - # self.strategy = strategy.CollaborativeEset() | |
151 | + self.strategy = strategy.ContentBased("half_eset",profile_size) | |
146 | 152 | elif strategy_str == "knn": |
147 | - self.strategy = strategy.Knn(self.cfg.k_neighbors) | |
153 | + self.strategy = strategy.Knn(k_neighbors) | |
148 | 154 | elif strategy_str == "knn_plus": |
149 | - self.strategy = strategy.KnnPlus(self.cfg.k_neighbors) | |
155 | + self.strategy = strategy.KnnPlus(k_neighbors) | |
150 | 156 | elif strategy_str == "knn_eset": |
151 | - self.strategy = strategy.KnnEset(self.cfg.k_neighbors) | |
157 | + self.strategy = strategy.KnnEset(k_neighbors) | |
152 | 158 | elif strategy_str == "knnco": |
153 | - self.strategy = strategy.KnnContent(self.cfg.k_neighbors) | |
159 | + self.strategy = strategy.KnnContent(k_neighbors) | |
154 | 160 | elif strategy_str == "knnco_eset": |
155 | - self.strategy = strategy.KnnContentEset(self.cfg.k_neighbors) | |
161 | + self.strategy = strategy.KnnContentEset(k_neighbors) | |
156 | 162 | # [FIXME: fix repository instanciation] |
157 | 163 | #elif strategy_str.startswith("demo"): |
158 | 164 | # self.strategy = strategy.Demographic(strategy_str) | ... | ... |