PearsonCorrelationSimilarity ClassNReco.Recommender Class Library
An implementation of the Pearson correlation.
Inheritance Hierarchy

System Object
  NReco.CF.Taste.Impl.Similarity AbstractItemSimilarity
    NReco.CF.Taste.Impl.Similarity AbstractSimilarity
      NReco.CF.Taste.Impl.Similarity PearsonCorrelationSimilarity

Namespace: NReco.CF.Taste.Impl.Similarity
Assembly: NReco.Recommender (in NReco.Recommender.dll) Version: (

public sealed class PearsonCorrelationSimilarity : AbstractSimilarity

The PearsonCorrelationSimilarity type exposes the following members.


Public methodPearsonCorrelationSimilarity(IDataModel)
Initializes a new instance of the PearsonCorrelationSimilarity class
Public methodPearsonCorrelationSimilarity(IDataModel, Weighting)
Initializes a new instance of the PearsonCorrelationSimilarity class

Public methodAllSimilarItemIDs (Inherited from AbstractItemSimilarity.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodItemSimilarities (Inherited from AbstractSimilarity.)
Public methodItemSimilarity (Inherited from AbstractSimilarity.)
Public methodRefresh (Inherited from AbstractSimilarity.)
Public methodSetPreferenceInferrer (Inherited from AbstractSimilarity.)
Public methodToString (Inherited from AbstractSimilarity.)
Public methodUserSimilarity (Inherited from AbstractSimilarity.)

For users X and Y, the following values are calculated:
  • sumX2: sum of the square of all X's preference values
  • sumY2: sum of the square of all Y's preference values
  • sumXY: sum of the product of X and Y's preference value for all items for which both X and Y express a preference
The correlation is then:

sumXY / sqrt(sumX2 * sumY2)

Note that this correlation "centers" its data, shifts the user's preference values so that each of their means is 0. This is necessary to achieve expected behavior on all data sets.

This correlation implementation is equivalent to the cosine similarity since the data it receives is assumed to be centered -- mean is 0. The correlation may be interpreted as the cosine of the angle between the two vectors defined by the users' preference values.

For cosine similarity on uncentered data, see UncenteredCosineSimilarity.

See Also