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
| Y= full (X);
[a,b]=size(Y);
fprintf('We have %4.0f users and %4.0f movies in the data set with %6.0f ratings.\n',a,b,a);
for i=1:b
fprintf('We have %4.0f users and %4.0f movies in the data set with %6.0f ratings.\n',i,b,a);
for j=1:a
fprintf('We have %4.0f users and %4.0f movies in the data set with %6.0f ratings.\n',i,j,a);
if(Y(j,i)==0)
pos=find(Y(j,i));
ind{i}=find(Y(:,i)>0);
P=Y(ind{i},:);
F=Y(j,:);
Mt=size(P);
u=zeros(Mt(1),1);
for k=1:Mt(1)
u(k)=P(k,:)*F'./(norm (P(k,:))* norm(F));
end
Y(j,i)=u'*P(:,i)/sum(u);
end
end
end
fprintf('We have %4.0f users and %4.0f movies in the data set with %6.0f ratings.\n',a,b,a);
B = csvread('ratings_test_eval_ID.csv');
Nr = length(B);
C = [B(:,1) zeros(Nr,1)];
k = 0;
for i = 1 : Nr
C(i,2) = Y(B(i,2), B(i,3));
if i/10000 == floor(i/10000),
fprintf('%6.0f...', i);
k = k+1;
if k/10 == floor(k/10);
fprintf('\n');
k = 0;
end
end
end
dlmwrite('results_cosfct.csv',C,'precision',7); |
Partager