A new machine learning algorithm automatically selected important risk-related variables of HIV from millions of medical records. The algorithm can detect those most vulnerable to HIV infection and could play an important role in increasing the prescription of preexposure prophylaxis medications to prevent infection.