code: def test_batch_rmse():
      import lenskit.crossfold as xf
      import lenskit.batch as batch
      import lenskit.algorithms.bias as bs
  
      ratings = lktu.ml100k.ratings
      algo = bs.Bias(damping=5)
  
      def eval(train, test):
          algo.fit(train)
          preds = batch.predict(algo, test)
          return preds.set_index(["user", "item"])
  
      results = pd.concat(
          (
              eval(train, test)
              for (train, test) in xf.partition_users(
                  ratings, 5, xf.SampleN(5)
              )
          )
      )
  
      user_rmse = results.groupby("user").apply(
          lambda df: pm.rmse(df.prediction, df.rating)
      )
  
      # we should have all users
      users = ratings.user.unique()
      assert len(user_rmse) == len(users)
      missing = np.setdiff1d(users, user_rmse.index)
      assert len(missing) == 0
  
      # we should not have any missing values
      assert all(user_rmse.notna())
  
      # we should have a reasonable mean
      assert user_rmse.mean() == approx(0.93, abs=0.05)
  
imports: import numpy
  import pandas
  import os.path
  from pytest import approx, raises, mark, skip
  import lenskit.metrics.predict
  import lenskit.util.test
label_desc: Use image node_id 17 for calling a global function with example usage: test_batch_rmse() and returns: preds