An adaptive optimal ensemble classifier via bagging and rank aggregation with applications to high dimensional data