Threshold optimization for classification in imbalanced data in a problem of gamma-ray astronomy