code: def test_sklearn_cv():
      model = LightFM(loss="warp", random_state=42)
  
      # Set distributions for hyperparameters
      randint = stats.randint(low=1, high=65)
      randint.random_state = 42
      gamma = stats.gamma(a=1.2, loc=0, scale=0.13)
      gamma.random_state = 42
      distr = {"no_components": randint, "learning_rate": gamma}
  
      # Custom score function
      def scorer(est, x, y=None):
          return precision_at_k(est, x).mean()
  
      # Dummy custom CV to ensure shape preservation.
      class CV(KFold):
          def split(self, X, y=None, groups=None):
              idx = np.arange(X.shape[0])
              for _ in range(self.n_splits):
                  yield idx, idx
  
      cv = CV(n_splits=3, shuffle=True, random_state=42)
      search = RandomizedSearchCV(
          estimator=model,
          param_distributions=distr,
          n_iter=2,
          scoring=scorer,
          random_state=42,
          cv=cv,
      )
      search.fit(train)
      assert search.best_params_["no_components"] == 58
  
imports: import pickle
  import numpy
  import scipy.sparse
  from scipy import stats
  from sklearn.metrics import roc_auc_score
  from sklearn.model_selection import KFold, RandomizedSearchCV
  from lightfm.lightfm import LightFM
  from lightfm.datasets import fetch_movielens
  from lightfm.evaluation import auc_score, precision_at_k
label_desc: Use image node_id 36 for calling a global function with example usage: test_sklearn_cv() and returns: precision_at_k