We demonstrate that a machine learning technique with a simple feedforward neural network can sensitively detect two successive phase transitions associated with the Berezinskii-Kosterlitz-Thouless (BKT) phase in q-state clock models simultaneously by analyzing the weight matrix components connecting the hidden and output layers. We find that the method requires only a data set of the raw spatial spin configurations for the learning procedure. This data set is generated by Monte-Carlo thermalizations at selected temperatures. Neither prior knowledge of, for example, the transition temperatures, number of phases, and order parameters nor processed data sets of, for example, the vortex configurations, histograms of spin orientations, and correlation functions produced from the original spin-configuration data are needed, in contrast with most of previously proposed machine learning methods based on supervised learning. Our neural network evaluates the transition temperatures as T_2/J=0.921 and T_1/J=0.410 for the paramagnetic-to-BKT transition and BKT-to-ferromagnetic transition in the eight-state clock model on a square lattice. Both critical temperatures agree well with those evaluated in the previous numerical studies.