-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
54 lines (41 loc) · 1.7 KB
/
main.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
import warnings
import numpy as np
from sklearn import datasets
from sklearn.metrics import accuracy_score, f1_score
from sklearn.naive_bayes import GaussianNB as Naive
from sklearn.tree import DecisionTreeClassifier as Tree
from sklearn.neighbors import KNeighborsClassifier as KNN
from src.ensemble import Ensemble
from src.flexcon import FlexConC
warnings.simplefilter("ignore")
# ssl = FlexConC(Naive(), verbose=True)
# rng = np.random.RandomState(42)
# iris = datasets.load_iris()
# random_unlabeled_points = rng.rand(iris.target.shape[0]) < 0.9
# iris.target_unlabelled = iris.target.copy()
# iris.target_unlabelled[random_unlabeled_points] = -1
# ssl.fit(iris.data, iris.target_unlabelled)
# y_pred = ssl.predict(iris.data[random_unlabeled_points, :])
# y_true = iris.target[random_unlabeled_points]
# print(
# f"ACC: {round(accuracy_score(y_true, y_pred), 4)}%\n"
# f'F1-Score: {round(f1_score(y_true, y_pred, average="macro"), 4)}%\n'
# f"Motivo da finalização: {ssl.termination_condition_}"
# )
comite = Ensemble()
comite.add_classifier(Naive())
comite.add_classifier(Tree())
comite.add_classifier(KNN())
rng = np.random.RandomState(42)
iris = datasets.load_iris()
random_unlabeled_points = rng.rand(iris.target.shape[0]) < 0.9
iris.target_unlabelled = iris.target.copy()
iris.target_unlabelled[random_unlabeled_points] = -1
comite.fit_ensembĺe(iris.data, iris.target_unlabelled)
y_pred = comite.predict(iris.data[random_unlabeled_points, :])
y_true = iris.target[random_unlabeled_points]
print(
f"ACC: {round(accuracy_score(y_true, y_pred), 4)}%\n"
f'F1-Score: {round(f1_score(y_true, y_pred, average="macro"), 4)}%\n'
f"Motivo da finalização: {comite.ensemble[0].termination_condition_}"
)