Calculating similarity between users using matlab

  • MATLAB
  • Thread starter Minaxi
  • Start date
  • Tags
    Matlab
In summary: But you do need to arrange things so that the calculations above make sense. See if you can do it!In summary, the conversation discusses the process of calculating the similarity between users in a database. This is done using a formula that takes into account age, gender, and occupation. The code for this process involves creating a matrix of similarities for each possible pairing of users. This can be done efficiently using a for loop and encoding all attributes as integers in the database.
  • #1
Minaxi
1
0
Hi all,
I am having database of 963 users .
Records of two users are

uid gender occupation age
1 F student 23
2 M teacher 30

Now i need to calculate the similarity of each user with every other as

sim(ui,uj)=0.8*sim(age) + 0.1*sim(gender) + 0.1*sim(occupation)


where sim(age)=1-[(Ai-Aj)/(agemax-agemin)];

agemax is the maximum age and agemin is minimum age of user.

sim(gender)=1 if G1=G2 else 0
sim(occup)=1 if occupation is same .


Kindly tell me the code fir it so that i can get a matrix of similarities.(963*963)
 
Physics news on Phys.org
  • #2
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.

Code:
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.
 
  • #3
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:

Code:
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:

Code:
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.
 

Related to Calculating similarity between users using matlab

What is the purpose of calculating similarity between users using Matlab?

The purpose of calculating similarity between users using Matlab is to identify patterns and relationships between users based on their preferences or behaviors. This can be useful in a variety of fields, such as recommendation systems, social network analysis, and market research.

What is the process for calculating similarity between users using Matlab?

The process for calculating similarity between users using Matlab typically involves selecting a similarity metric, such as Pearson correlation or cosine similarity, and applying it to a dataset containing user preferences or behaviors. This can be done using built-in functions in Matlab or by writing custom code.

How accurate are the results from calculating similarity between users using Matlab?

The accuracy of the results from calculating similarity between users using Matlab depends on the quality of the data and the chosen similarity metric. In general, the results can be quite accurate if the data is well-curated and the appropriate similarity metric is selected.

What are some potential challenges when calculating similarity between users using Matlab?

Some potential challenges when calculating similarity between users using Matlab include dealing with missing or incomplete data, choosing the most appropriate similarity metric for the given data, and scaling the calculation for large datasets.

Can the results from calculating similarity between users using Matlab be used for making predictions?

Yes, the results from calculating similarity between users using Matlab can be used for making predictions. For example, in a recommendation system, the calculated similarity between users can be used to suggest items or content that a user may be interested in based on their similarity to other users who have already shown interest in those items or content.

Back
Top