Subsurface petrophysical properties usually differ between different reservoirs, which affects lithology identification, especially for unconventional reservoirs. Thus, the lithology identification of subsurface reservoirs is a challenging task. Machine learning can be regarded as an effective method for using existing data for lithology prediction. By combining the hidden Markov model and random forests, we have adopted a novel method for lithology identification. The hidden Markov model provides a new hidden feature from elastic parameters, which is associated with unsupervised learning. Because elastic parameters are determined by petrophysical properties, the hidden feature may reveal an inner relationship of the petrophysical properties, which can expand the sample space. Then, with the new feature and the elastic parameters, the random forest method is adopted for lithology identification. In the prediction framework, the parameters of the hidden Markov model are updated until a satisfactory hidden feature is obtained. By analysis of synthetic and well-logging data, the superiority of the proposed method is demonstrated. Field seismic data application further proves the validity of the method. Numerical results show that the predicted lithology and shale content match well with real logging data.