Contextual Bandits In Imperfect Environments: Analysis And Applications