GClasses
GClasses::GInstanceRecommender Class Reference

Detailed Description

This class makes recommendations by finding the nearest-neighbors (as determined by evaluating only overlapping ratings), and assuming that the ratings of these neighbors will be predictive of your ratings.

#include <GRecommender.h>

Inheritance diagram for GClasses::GInstanceRecommender:
GClasses::GCollaborativeFilter

Public Member Functions

 GInstanceRecommender (size_t neighbors)
 
 GInstanceRecommender (const GDomNode *pNode, GLearnerLoader &ll)
 
virtual ~GInstanceRecommender ()
 
void clearUserDEPQ ()
 This method clears the priority queue that keeps track of the neighbors for a user. This will help speed up the search for each neighbor. It is used in the content-boosted filter since it is a dense matrix and should not change based on which item a rating is being asked for. More...
 
multimap< double, ArrayWrappergetNeighbors (size_t user, size_t item)
 This is the same function as predict except that it returns the the priority queue for the nearest neigbors. The values are further user by the content-boosted cf prediction method to combine the content-based and cf predictions. More...
 
double getRating (size_t user, size_t item)
 Get the rating of an item for a user. More...
 
virtual void impute (GVec &vec, size_t dims)
 See the comment for GCollaborativeFilter::impute. More...
 
GSparseSimilaritymetric ()
 Returns the current similarity metric. (This might be useful, for example, if you want to modify the regularization value.) More...
 
virtual double predict (size_t user, size_t item)
 See the comment for GCollaborativeFilter::predict. More...
 
virtual GDomNodeserialize (GDom *pDoc) const
 See the comment for GCollaborativeFilter::serialize. More...
 
void setMetric (GSparseSimilarity *pMetric, bool own)
 Sets the similarity metric to use. if own is true, then this object will take care of deleting it as appropriate. More...
 
void setSigWeight (size_t sig)
 Set the value for significance weighting. The default value is zero. If there are fewer matching items between users than the specified values, the similarity is scaled by numMathces/sigWeight. More...
 
virtual void train (GMatrix &data)
 See the comment for GCollaborativeFilter::train. More...
 
- Public Member Functions inherited from GClasses::GCollaborativeFilter
 GCollaborativeFilter ()
 
 GCollaborativeFilter (const GDomNode *pNode, GLearnerLoader &ll)
 
virtual ~GCollaborativeFilter ()
 
void basicTest (double minMSE)
 Performs a basic unit test on this collaborative filter. More...
 
double crossValidate (GMatrix &data, size_t folds, double *pOutMAE=NULL)
 This randomly assigns each rating to one of the folds. Then, for each fold, it calls train with a dataset that contains everything except for the ratings in that fold. It predicts values for the items in the fold, and returns the mean-squared difference between the predictions and the actual ratings. If pOutMAE is non-NULL, it will be set to the mean-absolute error. More...
 
GMatrixprecisionRecall (GMatrix &data, bool ideal=false)
 This divides the data into two equal-size parts. It trains on one part, and then measures the precision/recall using the other part. It returns a three-column data set with recall scores in column 0 and corresponding precision scores in column 1. The false-positive rate is in column 2. (So, if you want a precision-recall plot, just drop column 2. If you want an ROC curve, drop column 1 and swap the remaining two columns.) This method assumes the ratings range from 0 to 1, so be sure to scale the ratings to fit that range before calling this method. If ideal is true, then it will ignore your model and report the ideal results as if your model always predicted the correct rating. (This is useful because it shows the best possible results.) More...
 
GRandrand ()
 Returns a reference to the pseudo-random number generator associated with this object. More...
 
double trainAndTest (GMatrix &train, GMatrix &test, double *pOutMAE=NULL)
 This trains on the training set, and then tests on the test set. Returns the mean-squared difference between actual and target predictions. More...
 
void trainDenseMatrix (const GMatrix &data, const GMatrix *pLabels=NULL)
 Train from an m-by-n dense matrix, where m is the number of users and n is the number of items. All attributes must be continuous. Missing values are indicated with UNKNOWN_REAL_VALUE. If pLabels is non-NULL, then the labels will be appended as additional items. More...
 

Static Public Member Functions

static void test ()
 Performs unit tests. Throws if a failure occurs. Returns if successful. More...
 
- Static Public Member Functions inherited from GClasses::GCollaborativeFilter
static double areaUnderCurve (GMatrix &data)
 Pass in the data returned by the precisionRecall function (unmodified), and this will compute the area under the ROC curve. More...
 

Protected Attributes

size_t m_neighbors
 
bool m_ownMetric
 
GBaselineRecommenderm_pBaseline
 
GSparseMatrixm_pData
 
GSparseSimilaritym_pMetric
 
size_t m_significanceWeight
 
std::map< size_t, std::multimap< double, ArrayWrapper > > m_user_depq
 
- Protected Attributes inherited from GClasses::GCollaborativeFilter
GRand m_rand
 

Additional Inherited Members

- Protected Member Functions inherited from GClasses::GCollaborativeFilter
GDomNodebaseDomNode (GDom *pDoc, const char *szClassName) const
 Child classes should use this in their implementation of serialize. More...
 

Constructor & Destructor Documentation

GClasses::GInstanceRecommender::GInstanceRecommender ( size_t  neighbors)
GClasses::GInstanceRecommender::GInstanceRecommender ( const GDomNode pNode,
GLearnerLoader ll 
)
virtual GClasses::GInstanceRecommender::~GInstanceRecommender ( )
virtual

Member Function Documentation

void GClasses::GInstanceRecommender::clearUserDEPQ ( )
inline

This method clears the priority queue that keeps track of the neighbors for a user. This will help speed up the search for each neighbor. It is used in the content-boosted filter since it is a dense matrix and should not change based on which item a rating is being asked for.

multimap<double,ArrayWrapper> GClasses::GInstanceRecommender::getNeighbors ( size_t  user,
size_t  item 
)

This is the same function as predict except that it returns the the priority queue for the nearest neigbors. The values are further user by the content-boosted cf prediction method to combine the content-based and cf predictions.

double GClasses::GInstanceRecommender::getRating ( size_t  user,
size_t  item 
)

Get the rating of an item for a user.

virtual void GClasses::GInstanceRecommender::impute ( GVec vec,
size_t  dims 
)
virtual
GSparseSimilarity* GClasses::GInstanceRecommender::metric ( )
inline

Returns the current similarity metric. (This might be useful, for example, if you want to modify the regularization value.)

virtual double GClasses::GInstanceRecommender::predict ( size_t  user,
size_t  item 
)
virtual
virtual GDomNode* GClasses::GInstanceRecommender::serialize ( GDom pDoc) const
virtual
void GClasses::GInstanceRecommender::setMetric ( GSparseSimilarity pMetric,
bool  own 
)

Sets the similarity metric to use. if own is true, then this object will take care of deleting it as appropriate.

void GClasses::GInstanceRecommender::setSigWeight ( size_t  sig)
inline

Set the value for significance weighting. The default value is zero. If there are fewer matching items between users than the specified values, the similarity is scaled by numMathces/sigWeight.

static void GClasses::GInstanceRecommender::test ( )
static

Performs unit tests. Throws if a failure occurs. Returns if successful.

virtual void GClasses::GInstanceRecommender::train ( GMatrix data)
virtual

Member Data Documentation

size_t GClasses::GInstanceRecommender::m_neighbors
protected
bool GClasses::GInstanceRecommender::m_ownMetric
protected
GBaselineRecommender* GClasses::GInstanceRecommender::m_pBaseline
protected
GSparseMatrix* GClasses::GInstanceRecommender::m_pData
protected
GSparseSimilarity* GClasses::GInstanceRecommender::m_pMetric
protected
size_t GClasses::GInstanceRecommender::m_significanceWeight
protected
std::map<size_t, std::multimap<double,ArrayWrapper> > GClasses::GInstanceRecommender::m_user_depq
protected