Spectral unmixing of hyperspectral images is one of the most important research fields in remote sensing. Recently, the direct use of spectral libraries in spectral unmixing is on increase by increasing the availability of the libraries. In this way the spectral unmixing problem is converted into a sparse regression problem that is time-consuming. This is due to the existence of irrelevant spectra in the library. So these spectra should be removed in some way. In the mentioned approach which is called sparse unmixing, we do not need an endmember extraction algorithm and determination of the number of endmembers priori. Since spectral libraries usually contain highly correlated spectra, the sparse unmixing approach leads to non-admissible solutions. On the other hand, most of the proposed solutions are not noise-resistant and do not reach to a sufficiently high sparse solution. In this paper, with the purpose of overcoming the problems above, at first a machine learning approach for spectral library pruning is introduced. The spectral library is clustered using k-means algorithm based on a simple and efficient new feature space. Subtractive clustering is used for determining the cluster centers of k-means algorithm. Three distance measures, Spectral angle distance, spectral distance similarity and spectral correlation similarity tested to select the best for k-means. Then the training data needed to learn a classifier are extracted by adding different noise levels to the clustered spectra. The label of the training data is determined based on the results of spectral library clustering. After learning the classifier, each pixel of the image is classified using it. This classified image will be used for pruning the spectral library. For testing the impact of classifier type on the result of unmixing, three classifiers, decision tree classifier, neural networks and k-nearest neighbours are compared. For pruning the library, the spectra with the labels that none of the image pixels belong to, are removed from spectral library. In this way, the candidate spectra present in the image are extracted. Now, a genetic algorithm will be used for sparse unmixing. Experimental results show that spectral library pruning enhances the performance of sparse unmixing algorithms. Moreover, using k-nearest neighbor in image classification step, gives better results in the final unmixing process. Genetic algorithm that used for sparse unmixing compared with OMP and SUnSAL algorithms, works well in noisy images.