Mahout recommendation 5-Representation of preference data

Source: Internet
Author: User

Preference object: a single user ID, item ID, and preference value for genericpreference

Preferencearray, which is an array of all preference values of a single user, implements genericpreferencearray

Sample Code:

Package mahout; import Org. apache. mahout. cf. taste. impl. model. genericuserpreferencearray; import Org. apache. mahout. cf. taste. model. preference; import Org. apache. mahout. cf. taste. model. preferencearray; public class testdata {public static void main (string [] ARGs) {// a set of user preferences, indicating all preferences associated with a user, it contains a single user ID, an item ID array, and a preference value array // The item ID array corresponds to the preference value array one by one. // Array size: 2 preferencearray user1prefs = new genericuserpreferencearray (2); // The associated user iduser1prefs. setuserid (0, 1l); // The first preference user1prefs. setitemid (0, 101l); user1prefs. setvalue (0, 2.0f); // The second preference user1prefs. setitemid (1, 102l); user1prefs. setvalue (1, 3.0f); // try to put the third/* user1prefs. setitemid (2, 103l); user1prefs. setvalue (2, 3.0f); */preference Pref = user1prefs. get (1); system. out. println (Pref. getuserid (); system. out. println (Pref. getitemid (); system. out. println (Pref. getvalue ());}}

Output:

1
102
3.0

Let's take a third look: It's abnormal.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2at org.apache.mahout.cf.taste.impl.model.GenericUserPreferenceArray.setItemID(GenericUserPreferenceArray.java:129)at mahout.TestData.main(TestData.java:23)

In addition, fastmap, fastbyidmap, and fastidset are embedded in the internal classes of mahout. If you want to use them, you can view the source code.

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.