SHARE
TWEET

Untitled

a guest May 24th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def create_submission(predictions, pred_file='data/preds.csv', sub_file='data/submission.csv', columns=None):
  2.     '''
  3.     Create csv file for submission from predictions
  4.     Args:
  5.         predictions (array-like): prediction (no. fo images x 30 keypoints)
  6.         pred_file (string): file path for prediction csv file
  7.         sub_file (string): file path for submission csv file
  8.         columns (dict): provided column names for submission file
  9.     '''
  10.     lookup = pd.read_csv('data/IdLookupTable.csv')
  11.     if columns == None:
  12.         columns = train_data.columns[:-1]
  13.     preds = pd.DataFrame(predictions,
  14.                          index=np.arange(1, len(predictions)+1),
  15.                          columns=columns)
  16.     preds.to_csv(pred_file)
  17.     locations = [preds.loc[image_id, feature_name]
  18.                  for image_id, feature_name
  19.                  in lookup[['ImageId', 'FeatureName']].values]
  20.     locations = [location if location < IMG_SIZE else IMG_SIZE for location in locations]
  21.     lookup.Location = pd.Series(locations)
  22.     lookup[['RowId', 'Location']].to_csv(sub_file, index=False)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top