# Calculating similarity between users using matlab

by Minaxi
Tags: matlab, similarity, users
 P: 1,212 the data import depends on the form of your database, but assuming you can do this and obtain a 4-by-963 cell array, you can do this using a pair of for loops, eg. sim = zeros(963); for i = 1:962 for j = i+1:963 sim(i,j) = [your specific sim function] end end this should give you a strictly triangular matrix of the result of every possible pairing.
 P: 46 Hi, if I were you I'd encode all attributes as integers, so that all records can be stored as rows in a matrix of type int. I'll assume that you've done this, and your database is a matrix "db" of size [numusers 4]. I'll let you work out the details of that. First, let me give names to the columns: g = db(:,2); % the genders, assuming male=1 female=2 o = db(:,3); % the occupations, assuming integers a = db(:,4); % the ages Now you can compute the pairwise similarity matrix, S, pretty quickly: G = g*g' ~= 1*2; O = bsxfun(@minus,o,o') == 0; A = 1-bsxfun(@minus,a,a')/(agemax-agemin); S = 0.8*A + 0.1*G + 0.1*O; This'll give a nice speedup over for-loops when the number of users gets very large.