-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize_reviews.m
55 lines (39 loc) · 1.73 KB
/
normalize_reviews.m
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
45
46
47
48
49
50
51
52
53
54
function [ normalized_reviews ] = normalize_reviews( reviews )
%NORMALIZE_REVIEWS Summary of this function goes here
% Detailed explanation goes here
% reviews: [ user ; course ; course_prof ; rating ; workload_rating ]
% average by course_prof and course
% remove course_prof bias from everyone, so it's as if everyone that
% took course X took it with the same prof! in this way we can act like
% each course is the same regardless of who taught it, which means
% DENSER DATA
num_courses = max(reviews(2,:));
num_course_profs = max(reviews(3,:));
% compute averages
course_avgs = zeros(1, num_courses);
course_counts = course_avgs;
course_prof_avgs = zeros(1, num_course_profs);
course_prof_counts = course_prof_avgs;
for i=1:size(reviews,2)
col = reviews(:,i);
course = col(2);
course_prof = col(3);
rating = col(4);
course_avgs(course) = course_avgs(course) + rating;
course_counts(course) = course_counts(course) + 1;
course_prof_avgs(course_prof) = course_prof_avgs(course_prof) + rating;
course_prof_counts(course_prof) = course_prof_counts(course_prof) + 1;
end
course_avgs = course_avgs ./ course_counts;
course_prof_avgs = course_prof_avgs ./ course_prof_counts;
% use averages to normalize reviews
normalized_reviews = reviews;
for i=1:size(reviews, 2)
col = reviews(:,i);
course = col(2);
course_prof = col(3);
rating = col(4);
normalized_reviews(4,i) = rating - (course_prof_avgs(course_prof) - course_avgs(course));
normalized_reviews(4,i) = min(5, max(1, normalized_reviews(4,i)));
end
end