How can we nudge people to not engage in unethical behaviors, such as hoarding and violating social distancing, during Covid-19? As past research on antecedents of unethical behavior did not provide a clear answer, we turned to machine learning to generate novel hypotheses. We trained a deep learning model to predict whether or not World Values Survey respondents perceived unethical behaviors as justifiable, based on their responses to 708 other questions. The model identified optimism about the future of humanity as one of the top predictors of unethicality. A pre-registered correlational study (N=218 US-residents) conceptually replicated this finding. A preregistered experiment (N=294 US-residents) provided causal support: participants who read a scenario conveying optimism about the Covid-19 pandemic were less willing to justify hoarding and violating social distancing guidelines. The findings suggest that optimism can help reduce unethicality, and document the utility of machine learning methods for generating novel hypotheses. Accepted for COVID-19 fast-track publication in Psychological Science.