Given a set A of n people, with each person having a preference list that ranks a subset of A as his/her acceptable partners in order of preference, we consider the Roommates Problem (rp) and the Marriage Problem (mp) of matching people with their partners. In rp there is no further restriction, while in mp only people with opposite genders can be matched. For a pair of matchings X and Y , let φ(X, Y ) denote the number of people who prefer the person they get matched by X to the person they get matched by Y , and define an unpopularity factor u(M ) of a matching M to be the maximum ratio φ(M ′ , M )/φ(M, M ′ ) among all other possible matchings M ′ . In this paper, we develop an algorithm to compute the unpopularity factor of a given matching in O(m √ n log 2 n) time for rp and in O(m √ n log n) time for mp, where m is the total length of people's preference lists. We also generalize the notion of unpopularity factor to the weighted setting where people are given different voting weights and show that our algorithm can be slightly modified to support that setting with the same running time.