Exemple #1
0
from __future__ import division
import csv
from PIL import Image
import sys
import image_util
import math

(train_set, train_label,
 count_label) = image_util.load_dataset(image_util.DS1_TRAIN_PATH,
                                        image_util.DS1_LABEL_SIZE)

first_entropy = 0

for i in range(image_util.DS1_LABEL_SIZE):
    p = count_label[i] / image_util.DS1_TRAIN_SIZE
    first_entropy = first_entropy - p * math.log(p, 2)

tree = {
    "index": -1,
    "outcome_0": -1,
    "outcome_1": -1,
    "node_0": [],
    "node_1": [],
    "parent": None,
    "note": -1
}
stack_of_features = []
stack_of_nodes = []

first_set = []
for i in range(image_util.DS1_TRAIN_SIZE):
Exemple #2
0
from __future__ import division
import csv
from PIL import Image
import sys
import image_util

train_label = []
train_set = []
train_count_label = []
(train_set, train_label, count_label) = image_util.load_dataset(image_util.DS2_TRAIN_PATH, image_util.DS2_LABEL_SIZE)

prior_els = []

for i in range(len(count_label)):
	el = []
	for j in range(len(train_set[0])):
		el.append(0)
	prior_els.append(el)

for i in range(len(train_set)):
	for j in range(len(train_set[0])):
		prior_els[train_label[i]][j] = prior_els[train_label[i]][j] + train_set[i][j]

val_label = []
val_set = []
val_count_label = []
(val_set, val_label, val_count_label) = image_util.load_dataset(image_util.DS2_VAL_PATH, image_util.DS2_LABEL_SIZE)

correct_count = 0

for row in range(image_util.DS2_VAL_SIZE):