code: def _predict_weighted_average(
      model, nitems, nrange, ratings, rated, targets
  ):
      "Weighted average prediction function"
      min_nbrs, max_nbrs = nrange
      scores = np.full(nitems, np.nan, dtype=np.float_)
  
      for i in prange(targets.shape[0]):
          iidx = targets[i]
          rptr = model.rowptrs[iidx]
          rend = model.rowptrs[iidx + 1]
  
          num = 0
          denom = 0
          nnbrs = 0
  
          for j in range(rptr, rend):
              nidx = model.colinds[j]
              if not rated[nidx]:
                  continue
  
              nnbrs = nnbrs + 1
              num = num + ratings[nidx] * model.values[j]
              denom = denom + np.abs(model.values[j])
  
              if max_nbrs > 0 and nnbrs >= max_nbrs:
                  break
  
          if nnbrs < min_nbrs:
              continue
  
          scores[iidx] = num / denom
  
      return scores
  
imports: from sys import intern
  import logging
  import warnings
  import pandas
  import numpy
  import scipy.sparse
  import scipy.sparse.linalg
  from csr import CSR, create_from_sizes, create_empty
  import csr.kernel
  from numba import njit, prange
  from numba.typed import List
  from lenskit import util, DataWarning, ConfigWarning
  from lenskit.data import sparse_ratings
  from lenskit.sharing import in_share_context
  from lenskit.util.parallel import is_mp_worker
  from lenskit.util.accum import kvp_minheap_insert, kvp_minheap_sort
  from .None import Predictor
label_desc: Use image node_id 6 for calling a global function with example usage: _predict_weighted_average(model, nitems, nrange, ratings, rated, targets) and returns: scores