Home > other >  Who has the recommendation system based on user or collaborative filtering algorithm and code analys
Who has the recommendation system based on user or collaborative filtering algorithm and code analys

Time:09-30

And a large data of great god give a recommendation system based on user or collaborative filtering algorithm and code analysis.
I have part of the code but don't know how to perform on the Eclipse answer!
1. The public class AggregateAndRecommendReducer extends Reducer {
.
Public viod reduce (VarLongWritable key Iterable Values, the Context Context) throws IOException, InterruptedException {
The Vector recommendationVector=null;
For (VectorWritable VectorWritable: values) {
RecommendationVector=recommendationVector==null?
VectorWritable. The get ();
RecommendationVector. Plus (bectorWritable. The get ());
}
Queue TopItems=new PriorityQueue (recommendationsPerUser + 1, Collections. ReverseOrder (ByValueRecommendedItemComparator. GetInstance ()));
Iterator RecommendationVectorIterator=recommendationVector. IterateNonZero ();
While (recommendationVectorIterator. HasNext ()) {
The vector. The Element Element=recommendationVectorIterator. Next ();
Int index=element. The index ();
A float value=https://bbs.csdn.net/topics/(float) element. The get ();
If (topItems. The size () & lt; RecommendationsPerUser) {
TopItems. Add (new GenericRecommendedItem (indexItemIDMap. Get (index), value));
}
Else if (value> TopItems. Peek (). The getValue ()) {
TopItems. Add (new GenericRecommendedItem (indexItemIDMap. Get (index), value));
TopItems. Poll ();
}
}
List Recommendations=new ArrayList (topItems. The size ());
Recommendations. AddAll (topItems);
Collections. Sort (recommendations, ByValueRecommendedItemComparator getInstance ());
Context. Write (key,
The new
RecommendedItemsWritable (recommendations));
}
}
2. The public class AggregateCombiner extends Reducer {public void the reduce (varLongWritable key Iterable Values, the Context Context) throws IOException, IniterruptedException {
The Vector partial=null;
For (VectorWritable VectorWritable: values) {
Partial=partial==null?
VectorWritable. The get () : partial. Plus (vectorWritable. The get ());
}
Context. Write (key, new VectorWritable (partial));
}
}
3. The public class CooccurrenceColumnWrapperMapper extends Mapper {
Public void map (IntWritable key, VectorWritable value, Context Context) throws IOException, IniterruptedException {
Context. Write (key, new VectorOrPrefWritable (value. The get ()));
}
}
4. The public class PartialMultiplyMapper extends Mapper {
Public void map (IntWritable key, VectorAndPrefsWritable VectorAndPrefsWritable, Context Context) throws IOException, InterruptedException {
The Vector cooccurrenceColumn=vectorAndPrefsWritable. GetVector ();
List UserIDs=vectorAndPrefsWritable. GetUserIDs ();
List PrefValues=vectorAndPrefsWritable. GetValues ();
for (int i=0; I<=userIDs. The size (); I++) {
Long userID=userIDs. Get (I);
Float prefValue=https://bbs.csdn.net/topics/prefValues.get (I);
The Vector partialProduct=cooccurrenceColumn. Times (prefValue);
Context. Write (new VarLongWritable (userID), new VectorWritable (partialProduct));
}
}
}
5. The public class UserVectorSplitterMapper extends Mapper {
Public void map (VarLongWritable key, VectorWritable key, the Context Context) throws IOException, InterruptedException {
Long userID=key. The get ();
The Vector userVector=value. The get ();
Iterator It=userVector. IterateNonZero ();
IntWritable itemIndexWritable=new IntWritable ();
While (it. HasNext ()) {
Vector Element e=it, next ();
Int itemIndex=e.i ndex ();
Float preferenceValue=https://bbs.csdn.net/topics/(float) um participant et ();
ItemIndexWritable. Set (itemIndex);
Context. Write (itemIndexWritable, new VectorOrPrefWritable (userID, preferenceValue));
}
}
}
6. Public UserVectorToCooccurrenceMapper extends Mapper {
Public void map (VarLongWritable userID, VectorWritable userVector, Context Context) throws IOException, InterruptedException {Iterator It=userVector. The get (). IterateNonZero ();
While (it. HasNext ()) {
Int index1=it. Next (). The index ();
Iterator It2=userVector. The get (). IterateNonZero ();
While (it2. HasNext ()) {
Int index2=it2. Next (0. The index ();
The context. Write (new IntWritable (index1), new IntWritable (index2));
}
}
}
7.
Public UserVectorToCooccurrenceReducer extends Reducer {
Public void the reduce (Intwritable itemIndex1 Iterable ItemIndex2s, Context Context) throws IOException, InterruptedException {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related