code: def test_als_implicit_batch_accuracy():
      import lenskit.crossfold as xf
      from lenskit import batch
      from lenskit import topn
  
      ratings = lktu.ml100k.ratings
  
      def eval(train, test):
          train = train.astype({"rating": np.float_})
          _log.info("training CG")
          cg_algo = als.ImplicitMF(25, iterations=20, method="cg")
          cg_algo = Recommender.adapt(cg_algo)
          cg_algo.fit(train)
          _log.info("training LU")
          lu_algo = als.ImplicitMF(25, iterations=20, method="lu")
          lu_algo = Recommender.adapt(lu_algo)
          lu_algo.fit(train)
          users = test.user.unique()
          _log.info("testing %d users", len(users))
          cg_recs = batch.recommend(cg_algo, users, 100, n_jobs=2)
          lu_recs = batch.recommend(lu_algo, users, 100, n_jobs=2)
          return pd.concat(
              {"CG": cg_recs, "LU": lu_recs}, names=["Method"]
          ).reset_index("Method")
  
      folds = list(xf.partition_users(ratings, 5, xf.SampleFrac(0.2)))
      test = pd.concat(te for (tr, te) in folds)
      recs = pd.concat(
          (eval(train, test) for (train, test) in folds),
          ignore_index=True,
      )
  
      _log.info("analyzing recommendations")
      rla = topn.RecListAnalysis()
      rla.add_metric(topn.ndcg)
      results = rla.compute(recs, test)
      results = results.groupby("Method")["ndcg"].mean()
      _log.info("LU nDCG for users is %.4f", results.loc["LU"].mean())
      _log.info("CG nDCG for users is %.4f", results.loc["CG"].mean())
      assert all(results > 0.28)
      assert results.loc["LU"] == approx(results.loc["CG"], rel=0.05)
  
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 15 for calling a global function with example usage: test_als_implicit_batch_accuracy() and returns: pd