Spectrum sensing is of crucial importance in cognitive radio (CR) networks. In this paper, a reliable spectrum sensing scheme is proposed, which uses K-nearest neighbor, a machine learning algorithm. In the training phase, each CR user produces a sensing report under varying conditions and, based on a global decision, either transmits or stays silent. In the training phase the local decisions of CR users are combined through a majority voting at the fusion center and a global decision is returned to each CR user. A CR user transmits or stays silent according to the global decision and at each CR user the global decision is compared to the actual primary user activity, which is ascertained through an acknowledgment signal. In the training phase enough information about the surrounding environment, i.e., the activity of PU and the behavior of each CR to that activity, is gathered and sensing classes formed. In the classification phase, each CR user compares its current sensing report to existing sensing classes and distance vectors are calculated. Based on quantitative variables, the posterior probability of each sensing class is calculated and the sensing report is classified into either representing presence or absence of PU. The quantitative variables used for calculating the posterior probability are calculated through K-nearest neighbor algorithm. These local decisions are then combined at the fusion center using a novel decision combination scheme, which takes into account the reliability of each CR user. The CR users then transmit or stay silent according to the global decision. Simulation results show that our proposed scheme outperforms conventional spectrum sensing schemes, both in fading and in nonfading environments, where performance is evaluated using metrics such as the probability of detection, total probability of error, and the ability to exploit data transmission opportunities.