-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
27 lines (23 loc) · 1.01 KB
/
test.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
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from lib.SequentialDecisionTreeAlgorithm import SequentialDecisionTreeAlgorithm
from lib.SequentialModelAlgorithm import SequentialModelAlgorithm
dataset = pd.read_csv('./datasets/adultDataset.csv', header = 0)
attr_cols = dataset.loc[:, 'capital-gain':'native-country']
obj_col = dataset['income']
values = [5, 10, 15, 20]
print('\n--- Increasing nmodels ['+str(np.min(values))+' - '+str(np.max(values))+'] ---')
scores = []
for v in range(len(values)):
model = SequentialModelAlgorithm(nmodels = values[v], method = "knn")
submodels, score = model.start(attributes_cols = attr_cols, objetive_col = obj_col)
scores.append(score)
# We plot a tree to deterinate how ntree affects to the final score
plt.plot(values, scores)
plt.xlabel('- nmodels -')
plt.ylabel('- Balanced Accuracy Score -')
plt.title('score depending on nmodels\' values')
plt.show()
m = np.argmax(scores)
print('Best score: '+str(scores[m])+' with value = '+str(values[m]))