Attachment 'sheet11.m'
Download 1 function sheet11
2
3 fprintf('loading data...');
4 X = load('alpha_train_x.txt');
5 Y = load('alpha_train_y.txt');
6
7 [N, D] = size(X);
8
9 fprintf('%d data points with %d features.\n', N, D);
10
11 P = randperm(N);
12
13 XE = X(P(N/2:end), :);
14 YE = Y(P(N/2:end), :);
15 X = X(P(1:N/2), :);
16 Y = Y(P(1:N/2), :);
17
18 size(X)
19 size(Y)
20 size(XE)
21 size(YE)
22
23 fprintf('training...');
24 % find reasonable values below!
25 epochs = ?;
26 iters = ?;
27 C = ?;
28 eta = ?;
29 C = linsvm_sgd(C, eta, epochs, iters, X, Y, XE, YE);
30
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %
33 % your solution below.
34 %
35 %
36
37 % Train a linear SVM with quadratic costs on the slack variables using
38 % stochastic gradient descent.
39 %
40 % Parameters:
41 % - eta: base value for eta
42 % - epochs: total number of runs through the data.
43 % - iters: number of iterations per epoch
44 % - X, Y: training data
45 % - XE, YE: test data (only for computing the progress)
46 %
47 % Plot the test errors on training and test data for each epoch.
48 function linsvm_sgd(C, eta, epochs, iters, X, Y, XE, YE)
49 % ...
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.