code: def test_als_recs_topn_for_new_users_with_new_ratings(rng):
      """
      Test if ImplicitMF topn recommendations using the same ratings for a new user
      is the same as a user in ml-latest-small dataset.
      The test is run for more than one user.
      """
      from lenskit.algorithms import basic
      import scipy.stats as stats
  
      n_users = 10
      new_u_id = -1
      ratings = lktu.ml_test.ratings
  
      users = rng.choice(np.unique(ratings.user), n_users)
  
      algo = als.ImplicitMF(
          20, iterations=10, method="lu", use_ratings=True
      )
      rec_algo = basic.TopN(algo)
      rec_algo.fit(ratings)
      # _log.debug("Items: " + str(items))
  
      correlations = pd.Series(np.nan, index=users)
      for u in users:
          recs = rec_algo.recommend(u, 10)
          user_data = ratings[ratings.user == u]
          upos = algo.user_index_.get_loc(u)
          _log.info("user %s: %s ratings", u, len(user_data))
  
          _log.debug(
              "user_features from fit: "
              + str(algo.user_features_[upos, :])
          )
  
          # get the user's rating series
          new_ratings = user_data.set_index("item")["rating"].copy()
          new_recs = rec_algo.recommend(
              new_u_id, 10, ratings=new_ratings
          )
  
          # merge new & old recs
          all_recs = pd.merge(
              recs.rename(columns={"score": "old_score"}),
              new_recs.rename(columns={"score": "new_score"}),
              how="outer",
          ).fillna(-np.inf)
  
          tau = stats.kendalltau(all_recs.old_score, all_recs.new_score)
          _log.info("correlation for user %s: %f", u, tau.correlation)
          correlations.loc[u] = tau.correlation
  
      _log.debug("correlations: %s", correlations)
  
      assert not (any(correlations.isnull()))
      assert all(correlations >= 0.5)
  
imports: import logging
  from lenskit import util
  from lenskit.algorithms import als
  import pandas
  import numpy
  from scipy import stats
  import binpickle
  from seedbank import numpy_rng
  from pytest import mark, approx
  import lenskit.util.test
  from lenskit.algorithms import Recommender
  from lenskit.util import Stopwatch
label_desc: Use image node_id 6 for calling a global function with example usage: test_als_recs_topn_for_new_users_with_new_ratings(rng) without return types