-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_real.py
56 lines (36 loc) · 1.34 KB
/
main_real.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
55
56
from river import dummy, tree, forest, evaluate, metrics
import pandas as pd
def itfunc(features, labels, k):
for i in range(k):
x = {idx:feature for idx,feature in enumerate(features.loc[i])}
y = labels[i]
yield x, y
def train_model(model, features, labels, metric):
dataset = iter(itfunc(features, labels, len(labels)))
output = evaluate.progressive_val_score(dataset, model, metric)
print(output)
print(type(output))
print(output.get())
print(model.n_drifts_detected())
def retrieve_dataset(name: str):
data = pd.read_csv(f"USP/{name}.csv",header=None)
#retrieve labels
labels = data[8].to_list()
labels = [True if label==1 else False for label in labels]
#retrieve features
data = data.drop(data.columns[[0, 1, 8]], axis=1)
return data, labels
def main():
#get the necessary dataset
no_change_model = dummy.NoChangeClassifier()
EFDT_model = tree.ExtremelyFastDecisionTreeClassifier()
HATC_model = tree.HoeffdingAdaptiveTreeClassifier(seed=42)
ARF_model = forest.ARFClassifier(seed=42)
#get the necessary models
name = "Electricity"
features, labels = retrieve_dataset(name)
#train models and evaluate
metric = metrics.Accuracy()
train_model(ARF_model, features, labels, metric)
if __name__ == '__main__':
main()