-
Notifications
You must be signed in to change notification settings - Fork 9
/
util.py
64 lines (48 loc) · 1.47 KB
/
util.py
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
62
63
64
def split(dataset, batch_size, split=0.2):
"""Splits the given dataset into training/validation.
Args:
dataset[torch dataloader]: Dataset which has to be split
batch_size[int]: Batch size
split[float]: Indicates ratio of validation samples
Returns:
train_set[list]: Training set
val_set[list]: Validation set
"""
index = 0
length = len(dataset)
train_set = []
val_set = []
for data, target in dataset:
if index <= (length * split):
train_set.append([data, target])
else:
val_set.append([data, target])
index += 1
return train_set, val_set
def accuracy(predictions, dataset):
"""Evaluates accuracy for given set of predictions and true labels.
Args:
predictions[torch tensor]: predictions made by classifier.
labels[torch tensor]: true labels of the dataset.
Returns:
accuracy[float]: accuracy of classifier.
"""
total = 0.0
correct = 0.0
for j in range(0, len(dataset)):
correct += (predictions[j].long() == dataset[j].long()).sum().item()
total += len(dataset[j])
return (correct / total) * 100
def plot(x, y):
"""Plots a graph of given x and y.
Args:
x:
y:
"""
pass
def histogram(x, y):
"""Plots a histogram for corresponding x and y:
Args:
x:
y:
"""