-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (33 loc) · 1.87 KB
/
index.js
File metadata and controls
44 lines (33 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var async = require('async');
var _ = require('underscore');
var dataHelper = require('./data-helper');
var similarityCoefficient = require('./lib/similarity-coefficient.js');
dataHelper.getData(function(err, data) {
if (err) {
throw _.isError(err) ? err : new Error(err);
}
var twoRandPersons = _.first(_.shuffle(data.people), 2);
console.log('\n Two random persons:');
console.log(twoRandPersons);
var personsCommonScores = dataHelper.commonPersonsScores(twoRandPersons, data.peopleScores);
console.log('\n Common scores between persons:');
console.log(personsCommonScores);
console.log('\n Persons similarity coefficients \n');
console.log('\t by euclideanDistance:', similarityCoefficient.euclideanDistance(personsCommonScores) );
console.log('\t by pearson corelation:', similarityCoefficient.pearsonCorelation(personsCommonScores) );
console.log('\t by jaccard index:', similarityCoefficient.jaccardIndex(twoRandPersons, data.peopleScores, personsCommonScores) );
function printPersonTopMatches(personTopMatches) {
_.each(personTopMatches, function (person) {
// console.log('\t ' + person.name);
// console.log('\t ' + person.relativeScore);
console.log('\t', person.name, ' \t \t \t ', person.relativeScore);
});
}
var topMatchesCount = 5;
var firstPersonTopMatches1 = dataHelper.personTopMatches(twoRandPersons[0], data.people, topMatchesCount, data.peopleScores, similarityCoefficient.euclideanDistance);
console.log('\n "' + twoRandPersons[0].name + '" similar people by euclideanDistance: \n');
printPersonTopMatches(firstPersonTopMatches1);
var firstPersonTopMatches2 = dataHelper.personTopMatches(twoRandPersons[0], data.people, topMatchesCount, data.peopleScores, similarityCoefficient.pearsonCorelation);
console.log('\n "' + twoRandPersons[0].name + '" similar people by pearson corelation: \n');
printPersonTopMatches(firstPersonTopMatches2);
});