Exemple #1
0
def mlp_predict(model_file_name, test_file_name, pred_file_name, n_dim):
  logger.info('loading test file')
  (test_set_x, test_set_y) = svm2numpy(test_file_name, n_dim)
  logger.info('predicting')
  f = open(pred_file_name, 'w')
  for label in get_y_pred(model_file_name, test_set_x):
    f.write(str(label)+'\n')
Exemple #2
0
def featdel(input_file_name, n_features, model_file_name):
  logger.info('loading input file: ' + input_file_name)
  x, y = svm2numpy(input_file_name, n_features)
  logger.info('deleting features')
  x_sum = x.sum(axis=0)
  model = []
  for idx in xrange(len(x_sum)):
    if x_sum[idx] == 0.0:
      model.append(idx)
  logger.info(('before deletion: %i, after deletion: %i') % (n_features, n_features - len(model)))
  logger.info('outputing model to file: ' + model_file_name)
  np.save(model_file_name, np.array(model))
Exemple #3
0
def gen_feat(input_file_name, n_features, model_file_name, output_file_name):
  logger.info('loading input file: ' + input_file_name)
  x, y = svm2numpy(input_file_name, n_features)
  logger.info('loading model file: ' + model_file_name)
  model = np.load(model_file_name)
  logger.info('outputing file: ' + output_file_name)
  x = np.delete(x, model, 1)
  f = open(output_file_name, 'w')
  for n in xrange(len(x)):
    output_str = str(y[n])
    for idx in xrange(len(x[n])):
      if x[n, idx] != 0:
        output_str = ('%s %i:%f') % (output_str, idx, x[n, idx])
    f.write(output_str + '\n')
Exemple #4
0
def gen_feat(input_file_name, n_features, model_file_name, output_file_name):
  logger.info('loading input file: ' + input_file_name)
  x, y = svm2numpy(input_file_name, n_features)
  logger.info('loading model file: ' + model_file_name)
  mask_idx = np.load(model_file_name)
  logger.info('len after selection: %i' % (len(mask_idx)))
  logger.info('outputing file: ' + output_file_name)
  f = open(output_file_name, 'w')
  for n in xrange(x.shape[0]):
    output_str = str(y[n])
    ptr = 1
    for idx in mask_idx:
      if x[n, int(idx)-1] != 0.0:
        output_str = ('%s %i:%f') % (output_str, ptr, x[n, int(idx)-1])
      ptr += 1
    f.write(output_str + '\n')