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 data = invertData(data, class) | |
indices = (data(:, end) == class); | |
data(indices, end) = 1; | |
data(~indices, end) = -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
function accuracy = WinnerTakesAll(actual, predict, class) | |
[m, n] = size(actual); | |
[maxP, classP] = max(predict, [], 2); | |
accuracy = 100 * sum(actual(:, n) == class(classP)') / m; |
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 accuracy = ovasvm(data, n) | |
data = shuffleData(data); | |
[train, test] = splitData(data); | |
[trainSet, valSet] = splitData(train); | |
[trainSet, valSet] = scaleData(trainSet, valSet); | |
A = 1:n; | |
C = [2^-10 2^-9 2^-8 2^-7 2^-6 2^-5 2^-4 2^-3 2^-2 2^-1 2^0 2^1 2^2 2^3 2^4 2^5 2^6 2^7 2^8 2^9 2^10]; | |
accuracy = []; |
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 data = shuffleData(data) | |
[m, n] = size(data); | |
indices = randperm(m); | |
data = data(indices, :); |
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 [train, test] = splitData(data) | |
[m, n] = size(data); | |
train = []; | |
test = []; | |
nTrain = round(m * 0.7); | |
train = data(1:nTrain, :); | |
test = data(nTrain + 1:m, :); |
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 [train, test] = scaleData(train, test) | |
[row, col] = size(train); | |
normalMax = 1; | |
normalMin = -1; | |
for i=1:(col-1) | |
realMax = max(train(:, i)); | |
realMin = min(train(:, i)); |
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 = knn(trainSet, testSet, k) | |
m = size(trainSet, 1); | |
n = size(testSet, 1); | |
predict = []; | |
for test=1:n | |
for train=1:m | |
Eulidist(train) = norm(testSet(test, 1:end-1) - trainSet(train, 1:end-1)); | |
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
public class Stack { | |
private int[] stack; | |
private int arrayLength; | |
private int current = -1; | |
public Stack(int arrayLength) { | |
this.arrayLength = arrayLength; | |
stack = new int[arrayLength]; | |
} | |
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
import java.util.Scanner; | |
class Node { | |
Node next; | |
int value; | |
Node (int value) { | |
this.value = value; | |
} | |
} |
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
import java.util.Scanner; | |
public class Queue { | |
public int size; | |
public int front = 0; | |
public int rear = -1; | |
public String[] queue; | |
Queue(int size) { | |
this.size = size; |
NewerOlder