Hi Jiang,

Mahout's userbased recommender make use of similarity of a user with other
users to arrive at what to recommend to him & in this specific case,uses
Pearson correlation coefficient calculated from the user ratings as a
similarity measure to form a neighborhood.It then estimates ratings for
unpicked items based on user similarity and ratings provided by neighbors.

A short answer is that if a user gets any recommendations totally depend on
the training data that you provide as input to the model.In this case,if
you expect 107 as a recommendation for user 5,there arent enough ratings
available for 107 in the user 5's neighborhood. If you modify your data as
below,you will get recommendations for user 5. (just add a dummy rating
2,107,5)

I have included some code snippet which demonstrate this idea of user
similarity and neighborhood .Hope this helps.

*Code:*
public class Test {

    public static void main(String args[]) throws Exception {
        String inFile = "F:\\hadoop\\data\\recsysinput.txt";
        DataModel dataModel = new FileDataModel(new File(inFile));
        UserSimilarity userSimilarity = new
PearsonCorrelationSimilarity(dataModel);
        UserNeighborhood userNeighborhood = new
NearestNUserNeighborhood(100, userSimilarity, dataModel);
        Recommender recommender = new
GenericUserBasedRecommender(dataModel, userNeighborhood, userSimilarity);

        for (int i = 1; i <= 5; i++) {
            List<RecommendedItem> recommendations =
recommender.recommend(i, 1);
            for(int j=1;j<=5 ;j++){
                System.out.println("Similarity between user:"+i+" and
user:"+j+ "= "+userSimilarity.userSimilarity(i, j));
                }
            System.out.println("recommend for user:" + i +" Neighborhood
Size:" + userNeighborhood.getUserNeighborhood(i).length);

            for (RecommendedItem recommendation : recommendations) {
                System.out.println(recommendation);
            }
        }
    }
}

*Input:*
1,101,5.0
1,102,3.0
1,103,2.5
2,101,2
2,102,2.5
2,103,5
2,104,2
2,107,5
3,101,2.5
3,104,4
3,105,4.5
3,107,5
4,101,5
4,103,3
4,104,4.5
4,106,4
5,101,4
5,102,3
5,103,2
5,104,4
5,105,3.5
5,106,4

*Output:*
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in
[jar:file:/D:/from%20D/MSR/Coursework/SEM2/Pattern%20Recognition/project/acadnet/mahout-distribution-0.7/mahout-distribution-0.7/mahout-examples-0.7-job.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/D:/from%20D/MSR/Coursework/SEM2/Pattern%20Recognition/project/acadnet/mahout-distribution-0.7/mahout-distribution-0.7/lib/slf4j-jcl-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/D:/from%20D/MSR/Coursework/SEM2/Pattern%20Recognition/project/acadnet/mahout-distribution-0.7/mahout-distribution-0.7/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
explanation.
log4j:WARN No appenders could be found for logger
(org.apache.mahout.cf.taste.impl.model.file.FileDataModel).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.
Similarity between user:1 and user:1= 1.0
Similarity between user:1 and user:2= -0.7642652566278799
Similarity between user:1 and user:3= NaN
Similarity between user:1 and user:4= 0.9999999999999998
Similarity between user:1 and user:5= 0.944911182523068
recommend for user:1 Neighborhood Size:3
RecommendedItem[item:104, value:5.0]
Similarity between user:2 and user:1= -0.7642652566278799
Similarity between user:2 and user:2= 0.9999999999999998
Similarity between user:2 and user:3= 0.8029550685469666
Similarity between user:2 and user:4= -0.9707253433941515
Similarity between user:2 and user:5= -0.9393939393939394
recommend for user:2 Neighborhood Size:4
RecommendedItem[item:106, value:4.0]
Similarity between user:3 and user:1= NaN
Similarity between user:3 and user:2= 0.8029550685469666
Similarity between user:3 and user:3= 1.0
Similarity between user:3 and user:4= -1.0
Similarity between user:3 and user:5= -0.6933752452815484
recommend for user:3 Neighborhood Size:3
RecommendedItem[item:106, value:4.0]
Similarity between user:4 and user:1= 0.9999999999999998
Similarity between user:4 and user:2= -0.9707253433941515
Similarity between user:4 and user:3= -1.0
Similarity between user:4 and user:4= 1.0
Similarity between user:4 and user:5= 0.8783100656536799
recommend for user:4 Neighborhood Size:4
RecommendedItem[item:107, value:5.0]
Similarity between user:5 and user:1= 0.944911182523068
Similarity between user:5 and user:2= -0.9393939393939394
Similarity between user:5 and user:3= -0.6933752452815366
Similarity between user:5 and user:4= 0.8783100656536799
Similarity between user:5 and user:5= 1.0
recommend for user:5 Neighborhood Size:4
RecommendedItem[item:107, value:5.0]



On Thu, Feb 13, 2014 at 10:57 AM, Koobas <koo...@gmail.com> wrote:

> 5 should get 107 as a recommendation, whether user-based or item-based.
> No clue why you're not getting it.
>
>
>
> On Wed, Feb 12, 2014 at 11:50 PM, jiangwen jiang <jiangwen...@gmail.com
> >wrote:
>
> > Hi, all:
> >
> > I try to user mahout api to make recommendations, but I find some userId
> > has no recommendations, why?
> >
> > here is my code
> > public static void main(String args[]) throws Exception {
> >         String inFile = "F:\\hadoop\\data\\recsysinput.txt";
> >         DataModel dataModel = new FileDataModel(new File(inFile));
> >         UserSimilarity userSimilarity = new
> > PearsonCorrelationSimilarity(dataModel);
> >         UserNeighborhood userNeighborhood = new
> > NearestNUserNeighborhood(100, userSimilarity, dataModel);
> >         Recommender recommender = new
> > GenericUserBasedRecommender(dataModel, userNeighborhood, userSimilarity);
> >
> >         for (int i = 1; i <= 5; i++) {
> >             List<RecommendedItem> recommendations =
> > recommender.recommend(i, 1);
> >
> >             System.out.println("recommend for user:" + i);
> >             for (RecommendedItem recommendation : recommendations) {
> >                 System.out.println(recommendation);
> >             }
> >         }
> >     }
> >
> >
> > input data(recsysinput.txt):
> > 1,101,5.0
> > 1,102,3.0
> > 1,103,2.5
> > 2,101,2
> > 2,102,2.5
> > 2,103,5
> > 2,104,2
> > 3,101,2.5
> > 3,104,4
> > 3,105,4.5
> > 3,107,5
> > 4,101,5
> > 4,103,3
> > 4,104,4.5
> > 4,106,4
> > 5,101,4
> > 5,102,3
> > 5,103,2
> > 5,104,4
> > 5,105,3.5
> > 5,106,4
> >
> > output:
> > recommend for user:1
> > RecommendedItem[item:104, value:5.0]
> > recommend for user:2
> > RecommendedItem[item:106, value:4.0]
> > recommend for user:3
> > RecommendedItem[item:106, value:4.0]
> > recommend for user:4
> > RecommendedItem[item:105, value:5.0]
> > recommend for user:5
> >
> > UserId 5 has no recommendations, is it right?
> > Can I get some recommendations for userId 5, even if the recommendation
> > results are not good enough?
> >
> > thanks
> > Regards!
> >
>

Reply via email to