org.mymedialite.itemrec
Class ItemKNN
java.lang.Object
org.mymedialite.itemrec.ItemRecommender
org.mymedialite.itemrec.KNN
org.mymedialite.itemrec.ItemKNN
- All Implemented Interfaces:
- java.lang.Cloneable, IItemSimilarityProvider, IRecommender
- Direct Known Subclasses:
- ItemAttributeKNN, WeightedItemKNN
public class ItemKNN
- extends KNN
- implements IItemSimilarityProvider
Unweighted k-nearest neighbor item-based collaborative filtering using cosine similarity.
This recommender does NOT support incremental updates.
Method Summary |
float |
getItemSimilarity(int item_id1,
int item_id2)
Get the similarity between two items. |
int[] |
getMostSimilarItems(int item_id,
int n)
Get the most similar items. |
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 java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
ItemKNN
public ItemKNN()
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 IDitem_id
- the item ID
- Returns:
- the predicted score/rating for the given user-item combination
getItemSimilarity
public float getItemSimilarity(int item_id1,
int item_id2)
- Description copied from interface:
IItemSimilarityProvider
- Get the similarity between two items.
- Specified by:
getItemSimilarity
in interface IItemSimilarityProvider
- Parameters:
item_id1
- the ID of the first itemitem_id2
- the ID of the second item
- Returns:
- the item similarity; higher means more similar
getMostSimilarItems
public int[] getMostSimilarItems(int item_id,
int n)
- Description copied from interface:
IItemSimilarityProvider
- Get the most similar items.
- Specified by:
getMostSimilarItems
in interface IItemSimilarityProvider
- Parameters:
item_id
- the ID of the itemn
- the number of similar items to return
- Returns:
- the items most similar to a given item
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.