parameters: (data)
return_statement: return xs, ys
docstring: By a given data computes x and y that can be used as an input to a
      linear SVM.
docstring_summary: By a given data computes x and y that can be used as an input to a
      linear SVM.
docstring_tokens: By a given data computes x and y that can be used as an input to a linear SVM .
function: def transform_data(data):
      """
      By a given data computes x and y that can be used as an input to a
      linear SVM.
      """
  
      grouped = data.groupby(data['SampleId'], sort=False)
  
      xs, ys = [], []
  
      # k is used to create a balanced samples set for better linear
      # separation.
      k = 1
      for _, group in grouped:
          features, relevances = group[FEATURES], group['Relevance']
  
          n, total = len(group), 0
          for _, (i, j) in enumerate(itertools.combinations(range(n), 2)):
              dr = relevances.iloc[j] - relevances.iloc[i]
              y = np.sign(dr)
              if y == 0:
                  continue
  
              x = np.array(features.iloc[j]) - np.array(features.iloc[i])
  
              # Need to multiply x by average drop in NDCG when i-th and
              # j-th are exchanged.
              x *= abs(dr * (1 / log(j + 2, 2) - 1 / log(i + 2, 2)))
  
              # This is needed to prevent disbalance in classes sizes.
              if y != k:
                  x = np.negative(x)
                  y = -y
  
              xs.append(x)
              ys.append(y)
              total += 1
              k = -k
  
          # Scales this group of features to equalize different search
          # queries.
          for i in range(-1, -total, -1):
              xs[i] = xs[i] / total
      return xs, ys
function_tokens: def transform_data ( data ) : grouped = data . groupby ( data [ 'SampleId' ] , sort = False ) xs , ys = [ ] , [ ] # k is used to create a balanced samples set for better linear # separation. k = 1 for _ , group in grouped : features , relevances = group [ FEATURES ] , group [ 'Relevance' ] n , total = len ( group ) , 0 for _ , ( i , j ) in enumerate ( itertools . combinations ( range ( n ) , 2 ) ) : dr = relevances . iloc [ j ] - relevances . iloc [ i ] y = np . sign ( dr ) if y == 0 : continue x = np . array ( features . iloc [ j ] ) - np . array ( features . iloc [ i ] ) # Need to multiply x by average drop in NDCG when i-th and # j-th are exchanged. x *= abs ( dr * ( 1 / log ( j + 2 , 2 ) - 1 / log ( i + 2 , 2 ) ) ) # This is needed to prevent disbalance in classes sizes. if y != k : x = np . negative ( x ) y = - y xs . append ( x ) ys . append ( y ) total += 1 k = - k # Scales this group of features to equalize different search # queries. for i in range ( - 1 , - total , - 1 ) : xs [ i ] = xs [ i ] / total return xs , ys