org.mymedialite.itemrec
Class UserKNN

java.lang.Object
  extended by org.mymedialite.itemrec.ItemRecommender
      extended by org.mymedialite.itemrec.KNN
          extended by org.mymedialite.itemrec.UserKNN
All Implemented Interfaces:
java.lang.Cloneable, IRecommender, IUserSimilarityProvider
Direct Known Subclasses:
UserAttributeKNN, WeightedUserKNN

public class UserKNN
extends KNN
implements IUserSimilarityProvider

k-nearest neighbor user-based collaborative filtering using cosine-similarity (unweighted). k=inf equals most-popular. This recommender does NOT support incremental updates.


Field Summary
 
Fields inherited from class org.mymedialite.itemrec.KNN
correlation, k, nearest_neighbors
 
Fields inherited from class org.mymedialite.itemrec.ItemRecommender
feedback, maxItemID, maxUserID
 
Constructor Summary
UserKNN()
           
 
Method Summary
 int[] getMostSimilarUsers(int user_id, int n)
          get the most similar users.
 float getUserSimilarity(int user_id1, int user_id2)
          get the similarity between two users.
 double predict(int user_id, int item_id)
          Predict the rating or score for a given user-item combination.
 java.lang.String toString()
          Return a string representation of the recommender
 void train()
          Learn the model parameters of the recommender from the training data
 
Methods inherited from class org.mymedialite.itemrec.KNN
loadModel, loadModel, saveModel, saveModel
 
Methods inherited from class org.mymedialite.itemrec.ItemRecommender
canPredict, clone, getFeedback, setFeedback
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UserKNN

public UserKNN()
Method Detail

train

public void train()
Description copied from interface: IRecommender
Learn the model parameters of the recommender from the training data

Specified by:
train in interface IRecommender
Specified by:
train in class ItemRecommender

predict

public double predict(int user_id,
                      int item_id)
Description copied from interface: IRecommender
Predict the rating or score for a given user-item combination.

Specified by:
predict in interface IRecommender
Specified by:
predict in class ItemRecommender
Parameters:
user_id - the user ID
item_id - the item ID
Returns:
the predicted score/rating for the given user-item combination

getUserSimilarity

public float getUserSimilarity(int user_id1,
                               int user_id2)
Description copied from interface: IUserSimilarityProvider
get the similarity between two users.

Specified by:
getUserSimilarity in interface IUserSimilarityProvider
Parameters:
user_id1 - the ID of the first user
user_id2 - the ID of the second user
Returns:
the user similarity; higher means more similar

getMostSimilarUsers

public int[] getMostSimilarUsers(int user_id,
                                 int n)
Description copied from interface: IUserSimilarityProvider
get the most similar users.

Specified by:
getMostSimilarUsers in interface IUserSimilarityProvider
Parameters:
user_id - the ID of the user
n - the number of similar users to return
Returns:
the users most similar to a given user

toString

public java.lang.String toString()
Description copied from interface: IRecommender
Return a string representation of the recommender

Specified by:
toString in interface IRecommender
Overrides:
toString in class ItemRecommender
Returns:
the class name and all hyperparameters, separated by space characters.