code: def ng_sampling(df, user_num, item_num, num_ng):
      data_X = df.values.tolist()
  
      # Calculate a dok matrix
      train_mat = sp.dok_matrix((user_num, item_num), dtype=np.int32)
      for row in data_X:
          train_mat[row[0], row[1]] = 1
  
      features_ps = data_X
      features_ng = []
      for x in features_ps:
          u = x[0]
          for t in range(num_ng):
              j = np.random.randint(item_num)
              while (u, j) in train_mat:
                  j = np.random.randint(item_num)
              features_ng.append([u, j])
  
      labels_ps = [1.0 for _ in range(len(features_ps))]
      labels_ng = [0.0 for _ in range(len(features_ng))]
  
      features_fill = features_ps + features_ng
      labels_fill = labels_ps + labels_ng
      data_XY = pd.DataFrame(
          data=features_fill, columns=["user", "item"], dtype=np.int64
      )
      data_XY["label"] = labels_fill
      return data_XY
  
file_path: BigDL/python/orca/tutorial/NCF/process_xshards.py
imports: import os
  import numpy
  import pandas
  import scipy.sparse
  from sklearn.model_selection import train_test_split
  from bigdl.orca.data.pandas import read_csv
  from bigdl.orca.data.transformer import StringIndexer, MinMaxScaler
label_desc: Use image node_id 1 for calling a global function with example usage: ng_sampling(df, user_num, item_num, num_ng) and returns: data_XY