AZ31 magnesium alloys from different suppliers usually have different chemistry and processing histories, causing variance in their mechanical properties. In this work, we establish the quantitative relationship between alloy compositions, processing parameters, and mechanical properties by machine learning. Based on the artificial neural network (ANN) and support vector machine (SVM) algorithms, two models were built using a dataset with 112 data. Both models achieved good accuracy in predicting yield strength (YS), ultimate tensile strength (UTS), and tensile elongation (EL). To test their generalization ability, a new AZ31 extruded alloy was fabricated, with its chemical composition and processing history being documented. The YS, UTS, and EL of this material were measured and compared with model predictions. Relative errors for YS, UTS, and EL were 5.4%, 23%, and 272% by the ANN model, and 28%, 25%, and 143% by the SVM model, respectively. The reasons for the overestimation of the mechanical properties are discussed.