random_and_mode.py 697 Bytes
Newer Older
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
"""
Try to "classify" samples based on random chance and always guessing
the most popular category.
"""
import random
from data import DataSet

most_pop = 'TennisSwing'

data = DataSet()
nb_classes = len(data.classes)

# Try a random guess.
nb_random_matched = 0
nb_mode_matched = 0
for item in data.data:
    choice = random.choice(data.classes)
    actual = item[1]

    if choice == actual:
        nb_random_matched += 1

    if actual == most_pop:
        nb_mode_matched += 1

random_accuracy = nb_random_matched / len(data.data)
mode_accuracy = nb_mode_matched / len(data.data)
print("Randomly matched %.2f%%" % (random_accuracy * 100))
print("Mode matched %.2f%%" % (mode_accuracy * 100))