In recent years, machine learning has been adopted to complex networks, but most existing works concern about the structural properties. To use machine learning to detect phase transitions and accurately identify the critical transition point associated with dynamical processes on complex networks thus stands out as an open and significant problem. Here we develop a framework combining supervised and unsupervised learning, incorporating proper sampling of training data set. In particular, using epidemic spreading dynamics on complex networks as a paradigmatic setting, we start from supervised learning alone and identify situations that degrade the performance. To overcome the difficulties leads to the idea of exploiting confusion scheme, effectively a combination of supervised and unsupervised learning. We demonstrate that the scheme performs well for identifying phase transitions associated with spreading dynamics on homogeneous networks, but the performance deteriorates for heterogeneous networks. To strive to meet this challenge leads to the realization that sampling the training data set is necessary for heterogeneous networks, and we test two sampling methods: one based on the hub nodes together with their neighbors and another based on k-core of the network. The end result is a general machine learning framework for detecting phase transition and accurately identifying the critical transition point, which is robust, computationally efficient, and universally applicable to complex networks of arbitrary size and topology. Extensive tests using synthetic and empirical networks verify the virtues of the articulated framework, opening the door to exploiting machine learning for understanding, detection, prediction, and control of complex dynamical systems in general.