Class: Suggestor::Algorithms::PearsonCorrelation

Inherits:
Object
  • Object
show all
Includes:
RecommendationAlgorithm
Defined in:
lib/suggestor/algorithms/pearson_correlation.rb

Overview

Instance Attribute Summary

Attributes included from RecommendationAlgorithm

#collection

Instance Method Summary collapse

Methods included from RecommendationAlgorithm

#initialize, #no_shared_items_between?, #recommented_related_items_for, #shared_items_between, #similar_items_to

Instance Method Details

#similarity_score_between(first, second) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/suggestor/algorithms/pearson_correlation.rb', line 35

def similarity_score_between(first, second)
  return 0.0 if no_shared_items_between?(first, second)

  calculate_all_sums_for(first, second)
  numerator = difference_from_total_and_normalize_values
  # 10.5 /    0.0 / 
  denominator = square_root_from_differences_of_sums

  return 0.0 if denominator == 0

  numerator / denominator

end