Mahout implementation of a gender-based item similarity measurement method genderitemsimilarity

Source: Internet
Author: User

<span style= "FONT-SIZE:18PX;" >/*** * @author yangxin * @date 2016/2/18 * @info a gender-based item similarity metric * For example: two males or two female profiles are very similar and set their similarity to 1.0. * The similarity between the male and female profiles is assumed to be-1.0. One or two unknown gender in the last pair of files is set to 0.0.  */package Unitfive;import Java.util.collection;import Org.apache.mahout.cf.taste.common.refreshable;import Org.apache.mahout.cf.taste.common.tasteexception;import Org.apache.mahout.cf.taste.impl.common.fastidset;import Org.apache.mahout.cf.taste.similarity.itemsimilarity;public class Genderitemsimilarity implements ItemSimilarity {  Private final Fastidset men;private final fastidset women;public genderitemsimilarity (fastidset men, Fastidset Women) {// TODO auto-generated Constructor stubthis.men = Men;this.women = women;} @Overridepublic Double itemsimilarity (long profileID1, long profileID2) throws Tasteexception {//TODO auto-generated met Hod Stubboolean Profile1isman = Isman (profileID1); if (Profile1isman = = null) return 0.0; Boolean Profile2isman = Isman (profileID2), if (Profile2isman = = null) retuRN 0.0;return Profile1isman = = Profile2isman? 1:1;} @Overridepublic double[] itemsimilarities (Long itemID1, long[] itemid2s) throws Tasteexception {//TODO auto-generated Method stubdouble[] result = new Double[itemid2s.length];for (int i = 0; i < itemid2s.length; i++) {Result[i] = Itemsimil Arity (ItemID1, itemid2s[i]);} return result;} /** * Do nothing inside this method */@Overridepublic void Refresh (collection<refreshable> arg0) {//TODO auto-generated method Stub}@o Verridepublic long[] Allsimilaritemids (Long arg0) throws Tasteexception {//TODO auto-generated method Stubreturn null;} Private Boolean Isman (long profileID) {if (Men.contains (profileID)) {return boolean.true;} if (Women.contains (profileID)) {return boolean.false;} return null;}} </span>

Mahout implementation of a gender-based item similarity measurement method genderitemsimilarity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.