In this paper, a novel spectrum allocation approach for cognitive radio networks (CRNs) is proposed. Based on a measure of inference performance as well as on a measure of quality-of-service, the association between secondary users (SUs) in the network and frequency bands licensed to primary users (PUs) is investigated. The problem is formulated as a matching game between SUs and PUs. In this game, SUs employ hypothesis testing to detect PUs' signals and, eventually, rank them based on the logarithm of the a posteriori probability ratio. A valuation that captures the ranking metric and rate over the PU-owned frequency bands is proposed to PUs in the form of credit or rewards by SUs. Using this proposal, a PU evaluates a utility function that it uses to build its association preferences. A distributed algorithm that allows both SUs and PUs to interact and self-organize into a stable and optimal matching is presented. Simulation results show that the proposed algorithm can improve: i) the sum of SUs' rates by up to 20% and 60% relative to the deferred acceptance algorithm and random channel allocation approach respectively, and ii) the sum of PUs' payoffs by up to 25% compared to the deferred acceptance algorithm. The results also show an improved convergence time.