-
Notifications
You must be signed in to change notification settings - Fork 0
/
auf42.m
61 lines (47 loc) · 1.11 KB
/
auf42.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
55
56
57
58
59
60
61
clear all;
close all;
clc;
% Daten einlesen
file = dlmread('prostatecancer.txt');
X_test = file(find(file(:,end)==0),:);
X_train = file(find(file(:,end)==1),:);
y_test = X_test(:,10);
y_train = X_train(:,10);
X_test = X_test(:,1:9);
X_train = X_train(:,1:9);
X_test(:,1) = 1;
X_train(:,1) = 1;
X_all = [X_test; X_train];
%%%%%%%%%%%%
% Aufgabe 1
%%%%%%%%%%%%
% X * a = y
% a berechnen
a = ((X_train'*X_train)^-1)*X_train'*y_train;
% Werte vorhersagen
y_predict = X_test * a;
% Quadratische Abweichung berechnen und ausgeben
error = y_test - y_predict;
q = error'*error
%%%%%%%%%%%%
% Aufgabe 2
%%%%%%%%%%%%
for i=1:8
subsets = nchoosek(1:8,i);
for j=1:size(subsets,1)
X = X_train(:,[1,subsets(j,:).+1]);
a = ((X'*X)^-1)*X'*y_train;
y_predict = X_all(:,[1,subsets(j,:).+1]) * a;
error = [y_test;y_train] - y_predict;
q = error'*error;
qs(j) = q;
figure(1);
plot(i,q,'xr');
hold on;
end
figure(2);
plot(i,min(qs),'xr');
hold on;
end
saveas(1,'plot1.png');
saveas(2,'plot2.png');