code: def test_uu_save_load(tmp_path):
      orig = knn.UserUser(30)
      _log.info("training model")
      orig.fit(ml_ratings)
  
      fn = tmp_path / "uu.model"
      _log.info("saving to %s", fn)
      with fn.open("wb") as f:
          pickle.dump(orig, f)
  
      _log.info("reloading model")
      with fn.open("rb") as f:
          algo = pickle.load(f)
  
      _log.info("checking model")
  
      # it should have computed correct means
      umeans = ml_ratings.groupby("user").rating.mean()
      mlmeans = pd.Series(
          algo.user_means_, index=algo.user_index_, name="mean"
      )
      umeans, mlmeans = umeans.align(mlmeans)
      assert mlmeans.values == approx(umeans.values)
  
      # we should be able to reconstruct rating values
      uir = ml_ratings.set_index(["user", "item"]).rating
      r_items = algo.transpose_matrix_.rowinds()
      ui_rbdf = pd.DataFrame(
          {
              "user": algo.user_index_[algo.transpose_matrix_.colinds],
              "item": algo.item_index_[r_items],
              "nrating": algo.transpose_matrix_.values,
          }
      ).set_index(["user", "item"])
      ui_rbdf = ui_rbdf.join(mlmeans)
      ui_rbdf["rating"] = ui_rbdf["nrating"] + ui_rbdf["mean"]
      ui_rbdf["orig_rating"] = uir
      assert ui_rbdf.rating.values == approx(ui_rbdf.orig_rating.values)
  
      # running the predictor should work
      preds = algo.predict_for_user(4, [1016])
      assert len(preds) == 1
      assert preds.index == [1016]
      assert preds.values == approx([3.62221550680778])
  
imports: from lenskit.algorithms import Recommender
  import lenskit.algorithms.user_knn
  from lenskit.util import clone
  from pathlib import Path
  import logging
  import pickle
  import pandas
  import numpy
  from scipy.sparse import linalg
  from pytest import approx, mark
  import lenskit.util.test
label_desc: Use image node_id 11 for calling a global function with example usage: test_uu_save_load(tmp_path) without return types