Add pessimistic tie breaks. Add groupby to cleanup code. Use ravel to
flatten pred arrays.