TypeError Traceback (most recent call last)
Cell In[45], line 3
1 get_ipython().run_line_magic('scrun', '')
2 for _r in recs:
----> 3 output = model.recommend(
4 _r
5 )
File ~/miniforge3/envs/wsknn/lib/python3.12/site-packages/wsknn/model/wsknn.py:276, in WSKNN.recommend(self, event_stream, settings)
273 if settings is not None:
274 self.set_model_params(**settings)
--> 276 recommendations = self._predict(event_stream)
278 return recommendations
File ~/miniforge3/envs/wsknn/lib/python3.12/site-packages/wsknn/model/wsknn.py:388, in WSKNN._predict(self, session)
387 def _predict(self, session):
--> 388 neighbors = self._nearest_neighbors(session)
390 if len(neighbors) == 0:
391 if self.recommend_any:
File ~/miniforge3/envs/wsknn/lib/python3.12/site-packages/wsknn/model/wsknn.py:629, in WSKNN._nearest_neighbors(self, session)
608 def _nearest_neighbors(self, session: List) -> List:
609 """Method searches for nearest neighbors for a given session.
610
611 Parameters
(...)
627 smaller than number of the closest sessions.
628 """
--> 629 possible_neighbor_sessions = self._possible_neighbors(session)
630 items_sequence = session[0]
631 rank = self._calculate_similarity(items_sequence, possible_neighbor_sessions)
File ~/miniforge3/envs/wsknn/lib/python3.12/site-packages/wsknn/model/wsknn.py:668, in WSKNN._possible_neighbors(self, session)
665 if self.required_sampling_event is not None:
666 common_sessions = self._get_sessions_with_event(common_sessions)
--> 668 sample_subset = self._sample_possible_neighbors(common_sessions, session)
669 return sample_subset
File ~/miniforge3/envs/wsknn/lib/python3.12/site-packages/wsknn/model/wsknn.py:815, in WSKNN._sample_possible_neighbors(self, all_sessions, session)
798 """Method samples possible neighbors.
799
800 Parameters
(...)
811 The subset of possible neighbors
812 """
814 if self.sampling_strategy == 'random':
--> 815 return self._sampling_random(all_sessions)
816 elif self.sampling_strategy == 'recent':
817 return self._sampling_recent(all_sessions)
File ~/miniforge3/envs/wsknn/lib/python3.12/site-packages/wsknn/model/wsknn.py:842, in WSKNN._sampling_random(self, sessions)
828 """Get random sessions from the sessions space. This method is good to estimate model performance.
829
830 Parameters
(...)
838 Random sample of ``self.possible_neighbors_sample_size`` sessions.
839 """
841 sample_size = min(self.possible_neighbors_sample_size, len(sessions))
--> 842 sample = random.sample(sessions, sample_size)
844 return sample
File ~/miniforge3/envs/wsknn/lib/python3.12/random.py:413, in Random.sample(self, population, k, counts)
389 # Sampling without replacement entails tracking either potential
390 # selections (the pool) in a list or previous selections in a set.
391
(...)
409 # too many calls to _randbelow(), making them slower and
410 # causing them to eat more entropy than necessary.
412 if not isinstance(population, _Sequence):
--> 413 raise TypeError("Population must be a sequence. "
414 "For dicts or sets, use sorted(d).")
415 n = len(population)
416 if counts is not None:
TypeError: Population must be a sequence. For dicts or sets, use sorted(d).