This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function[results] = ten_fold_cross_validation_parameter_estimation(x, y) | |
results = []; | |
% Train and pick the best tree using 10-fold cross validation. | |
%[x2, y2] = ANNdata(x, y); | |
for hidden_neurons_1 = 10:25 | |
hidden_neurons_1 | |
for hidden_neurons_2 = 10:25 | |
hidden_neurons_2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [ matrix ] = confusion_matrix(size, predicted, actual) | |
%CONFUSION_MATRIX Generates general confusion matrix | |
% User inputs size of expected matrix, get length of vector input | |
% For length of vector input, increment value of matrix with coordinates | |
% corresponding to value in vector row. | |
len = length(actual); | |
matrix = zeros(size); | |
predicted; | |
for n = 1:len | |
x = actual(n, :) + 1 ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Accepts as input network (net), examples | |
% (x2, same format as x) and | |
% combination method (combine_method) to | |
% produce a vector of label predictions. | |
function [predictions] = testANN(net, x2, combine_method) | |
predictions = sim(net, x2); | |
%predictions = combine_method(out); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Accepts as input network (net), examples | |
% (x2, same format as x) and | |
% combination method (combine_method) to | |
% produce a vector of label predictions. | |
function [predictions] = testANN(net, x2, combine_method) | |
predictions = sim(net, x2); | |
%predictions = combine_method(out); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://gist.github.com/limzunyuan/c0791bd7c2eb40ec56bf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [ rate ] = avg_classification_rate( matrix ) | |
%AVG_CLASSFICATION_RATE Calculates average classification rate | |
% CR is no. of correctly classified examples (trace) divided by | |
% total no. of examples (sum of matrix) | |
total = sum(sum(matrix)); | |
correct = trace(matrix); | |
rate = correct / total; | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [result] = avg_precision_rate(matrix) | |
dim = size(matrix, 1); | |
result = zeros(1, dim); | |
for n = 1:size(matrix, 1) | |
col = matrix(:, n); | |
tp = col(n); | |
denom = sum(col); | |
result(n) = tp/denom; | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Returns indices for training set and test set | |
% e.g. partition(1) => [1:900 , 901:1004] | |
function [training_idx testing_idx] = partition(ith_partition, x2) | |
nrows = size(x2, 2); | |
test_set_start_index = floor((ith_partition - 1) / 10 * nrows) + 1; | |
test_set_end_index = floor(ith_partition / 10 * nrows); | |
testing_idx = test_set_start_index:test_set_end_index; | |
training_idx = setdiff(1:nrows, testing_idx); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [results] = f1_measure(matrix) | |
precision = avg_precision_rate(matrix); | |
recall = avg_recall_rate(matrix); | |
dim = size(matrix, 1); | |
results = zeros(1, dim); | |
for i = 1 : dim | |
results(i) = 2 * precision(i) * recall(i) / (precision(i) + recall(i)); | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [net] = create_traingd(x, y, list_num_hidden_neurons, ... | |
num_epochs, train_idx, validation_idx, test_idx, lr) | |
%[x2, y2] = ANNdata(x, y); | |
net = feedforwardnet(list_num_hidden_neurons); | |
net = configure(net, x, y); | |
net.trainFcn = 'traingd'; | |
net.divideFcn = 'divideind'; | |
net.divideParam.trainInd = train_idx; | |
net.divideParam.valInd = validation_idx; | |
net.divideParam.testInd = test_idx; |
OlderNewer