%A = csvread('weinqualitaet.csv'); geht nicht wegen erster Zeile und nicht
%konventionelle csv-Datei (, ist nicht seperator)
A = dlmread('weinqualitaet.csv',';',1,0);
X = A(:,1:11);
y = A(:,12);
k = 200; % Anzahl von Trainingsbeispielen, die zum Training verwendet wird
% train KernelReg:
alpha = learnKernelReg(X(1:k,:)',y(1:k)',0.1,@rbf,2);
% Bestimme Label für Testinstanzen
Yeval = zeros(size(X,1) - k,1);
for i = 1:length(Yeval)
    Yeval(i) = classKernelReg(alpha,X(1:k,:)',@rbf,2,X(k+i,:)');
    A = input('blbl');
end
% Loss of Test
Ytest = y(k+1:end,:);
lossTest = (Ytest - Yeval).^2;
squaredLoss = sum(lossTest)/length(Yeval);


% Loss of Train
YtrainEval = zeros(k,1);
for i = 1:k
    YtrainEval(i) = classKernelReg(alpha,X(1:k,:)',@rbf,2,X(i,:)');
end
lossTrain = (y(1:k) - YtrainEval);
squaredLossTrain = sum(lossTrain)/k;

clear;
load('spect.mat');
k = 80;
% Label konvertieren
Ytr = 2*Ytr - 1;
Ytest = 2*Ytest - 1;

alpha = learnKernelReg(Xtr(1:k,:)',Ytr(1:k)',0.1,@rbf,2);
%alpha = learnKernelReg(Xtr(1:k,:)',Ytr(1:k)',0.6,@rbf,0.5);

Yeval = zeros(size(Xtr,1),1);
for i = 1:length(Yeval)
    Yeval(i) = sign(classKernelReg(alpha,Xtr(1:k,:)',@rbf,2,Xtr(i,:)'));
end
TrainAccuracy = 100*sum(Yeval == Ytr)/length(Ytr)


Yeval = zeros(size(Xtest,1),1);
for i = 1:length(Yeval)
    Yeval(i) = sign(classKernelReg(alpha,Xtr(1:k,:)',@rbf,2,Xtest(i,:)'));
end
% Loss of Test
Accuracy = 100*sum(Yeval == Ytest)/length(Ytest)