Women are driven out of physics at disproportionate rates, leading to a large gender gap in the field. There is much research examining the factors that push women out of physics, but there has been comparatively less investigation into what enables persistence of women in physics. In this dissertation, we study which affective factors correlate with persistence of women in physics. We also detail our efforts to create a machine learning tool to predict persistence. These findings allow professors to better aid women in their classes, increasing gender equity in the discipline. The data in this dissertation come from surveys given at and after the Conference for Undergraduate Women and Gender Minorities in Physics (CU*iP), in the form of an initial survey given to undergraduate women and a follow-up survey given years later. This survey contains 40 Likert-scale questions and one short answer question on motivation; in the process of analyzing the latter, we also studied the most common motivations of women to join physics, as well as how to autonomously code short answer questions using Natural Language Processing. We find that the factors that correlate most strongly with persistence of women in physics are interest, specifically interest in research, and initially joining physics because of explicit support from others. We also find two factors that correlate with leaving physics: sense of belonging and joining physics because of the culture of the field. With these data, we are able to make a machine learning tool that predicts persistence with around two-thirds accuracy. Finally, we find that the most common factors that lead to women joining physics are the intrinsic value of the field, the way doing physics makes them feel, and support or pressure from those around them.