code: def test_user_metric():
      import lenskit.crossfold as xf
      import lenskit.batch as batch
      from lenskit.algorithms.bias import Bias
  
      train, test = next(
          xf.sample_users(
              lktu.ml_test.ratings, 1, 200, xf.SampleFrac(0.5)
          )
      )
      algo = Bias()
      algo.fit(train)
  
      preds = batch.predict(algo, test)
  
      rmse = pm.user_metric(preds)
      u_rmse = preds.groupby("user").apply(
          lambda df: pm.rmse(df.prediction, df.rating)
      )
      assert rmse == approx(u_rmse.mean())
  
      mae = pm.user_metric(preds, metric=pm.mae)
      u_mae = preds.groupby("user").apply(
          lambda df: pm.mae(df.prediction, df.rating)
      )
      assert mae == approx(u_mae.mean())
  
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 19 for calling a global function with example usage: test_user_metric() without return types