File tree Expand file tree Collapse file tree 2 files changed +35
-20
lines changed Expand file tree Collapse file tree 2 files changed +35
-20
lines changed Original file line number Diff line number Diff line change 11
11
Theta = reshape(params(num_movies * num_features + 1 : end ), ...
12
12
num_users , num_features );
13
13
14
-
14
+
15
15
% You need to return the following values correctly
16
16
J = 0 ;
17
17
X_grad = zeros(size(X ));
41
41
%
42
42
43
43
44
+ J = sum(sum( (( (X * Theta ' ) - Y ) .* R ) .^ 2 ))/2 ;
44
45
46
+ X_grad = (( (X * Theta ' ) - Y ) .* R ) * Theta ;
47
+ Theta_grad = (( (X * Theta ' ) - Y ) .* R )' * X ;
45
48
46
49
50
+ % Regularization
51
+ J = J + lambda * (Theta(: )' * Theta(: )) / 2 ;
52
+ J = J + lambda * (X(: )' * X(: )) / 2 ;
47
53
48
-
49
-
50
-
51
-
52
-
53
-
54
+ X_grad = X_grad + lambda * X ;
55
+ Theta_grad = Theta_grad + lambda * Theta ;
54
56
55
57
56
58
Original file line number Diff line number Diff line change 126
126
% Initialize my ratings
127
127
my_ratings = zeros(1682 , 1 );
128
128
129
- % Check the file movie_idx.txt for id of each movie in our dataset
130
- % For example, Toy Story (1995) has ID 1, so to rate it "4", you can set
131
- my_ratings(1 ) = 4 ;
132
-
133
- % Or suppose did not enjoy Silence of the Lambs (1991), you can set
134
- my_ratings(98 ) = 2 ;
135
-
136
- % We have selected a few movies we liked / did not like and the ratings we
137
- % gave are as follows:
138
- my_ratings(7 ) = 3 ;
129
+ % % Check the file movie_idx.txt for id of each movie in our dataset
130
+ % % For example, Toy Story (1995) has ID 1, so to rate it "4", you can set
131
+ % my_ratings(1) = 4;
132
+ %
133
+ % % Or suppose did not enjoy Silence of the Lambs (1991), you can set
134
+ % my_ratings(98) = 2;
135
+ %
136
+ % % We have selected a few movies we liked / did not like and the ratings we
137
+ % % gave are as follows:
138
+ % my_ratings(7) = 3;
139
+ % my_ratings(12)= 5;
140
+ % my_ratings(54) = 4;
141
+ % my_ratings(64)= 5;
142
+ % my_ratings(66)= 3;
143
+ % my_ratings(69) = 5;
144
+ % my_ratings(183) = 4;
145
+ % my_ratings(226) = 5;
146
+ % my_ratings(355)= 5;
147
+
148
+
149
+ my_ratings(1 ) = 5 ;
150
+ my_ratings(7 ) = 5 ;
139
151
my_ratings(12 )= 5 ;
140
152
my_ratings(54 ) = 4 ;
141
153
my_ratings(64 )= 5 ;
142
154
my_ratings(66 )= 3 ;
143
155
my_ratings(69 ) = 5 ;
144
- my_ratings(183 ) = 4 ;
145
- my_ratings(226 ) = 5 ;
146
- my_ratings(355 )= 5 ;
156
+ my_ratings(98 ) = 4 ;
157
+ my_ratings(183 ) = 3 ;
158
+ my_ratings(226 ) = 4 ;
159
+ my_ratings(355 )= 4 ;
147
160
148
161
fprintf(' \n\n New user ratings:\n ' );
149
162
for i = 1 : length(my_ratings )
You can’t perform that action at this time.
0 commit comments