-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdirichlet_glass.py
33 lines (29 loc) · 1.06 KB
/
gdirichlet_glass.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
# %%
from random import seed
from naive_bayes import load_list, load_csv, continuous_column_to_float, ten_bin_discretization, descrete_column_to_int, cross_validation_split, gdirichlet_prior_nb
import logging
# %%
log_file = 'log/gdirichlet.log'
logging.basicConfig(format='%(message)s',
filename=log_file, level=logging.DEBUG)
logging.getLogger().addHandler(logging.StreamHandler())
logging.info('''=============================================
generalized dirichlet-glass
=============================================''')
# %%
seed(1)
filename = 'ranked_attr/glass.txt'
ranked_attributes = load_list(filename)
filename = 'csv/glass.csv'
dataset = load_csv(filename)
for i in range(len(dataset[0])-1):
continuous_column_to_float(dataset, i)
ten_bin_discretization(dataset, i)
# convert class column to integers
descrete_column_to_int(dataset, len(dataset[0])-1)
# evaluate algorithm
k_values = [10]*9
n_folds = 5
folds = cross_validation_split(dataset, n_folds)
ranked_columns, avg_score = gdirichlet_prior_nb(
folds, k_values, ranked_attributes)