text: import numpy as np
  
  def readMatrix(file):
      fd = open(file, 'r')
      hdr = fd.readline()
      rows, cols = [int(s) for s in fd.readline().strip().split()]
      tokens = fd.readline().strip().split()
      matrix = np.zeros((rows, cols))
      Y = []
      for i, line in enumerate(fd):
          nums = [int(x) for x in line.strip().split()]
          Y.append(nums[0])
          kv = np.array(nums[1:])
          k = np.cumsum(kv[:-1:2])
          v = kv[1::2]
          matrix[i, k] = v
      return matrix, tokens, np.array(Y)
  
  def nb_train(matrix, category):
      state = {}
      N = matrix.shape[1]
      ###################
  
      ###################
      return state
  
  def nb_test(matrix, state):
      output = np.zeros(matrix.shape[0])
      ###################
  
      ###################
      return output
  
  def evaluate(output, label):
      error = (output != label).sum() * 1. / len(output)
      print 'Error: %1.4f' % error
  
  def main():
      trainMatrix, tokenlist, trainCategory = readMatrix('./data/MATRIX.TRAIN')
      testMatrix, tokenlist, testCategory = readMatrix('./data/MATRIX.TEST')
  
      state = nb_train(trainMatrix, trainCategory)
      output = nb_test(testMatrix, state)
  
      evaluate(output, testCategory)
      return
  
  if __name__ == '__main__':
      main()
  