Skip to content

Commit

Permalink
MOA E2
Browse files Browse the repository at this point in the history
  • Loading branch information
JKomorniczak committed Oct 31, 2023
1 parent 8ca598f commit 53c7a3d
Show file tree
Hide file tree
Showing 222 changed files with 135 additions and 300,039 deletions.
78 changes: 78 additions & 0 deletions E_MOA_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
E2 - classification for MOA streams
"""

import numpy as np
from sklearn import clone
from sklearn.model_selection import RepeatedStratifiedKFold
from sklearn.neural_network import MLPClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from tqdm import tqdm
from sklearn.metrics import balanced_accuracy_score
import os

np.random.seed(1233)

measures = ["clustering",
"complexity",
"concept",
"general",
"info-theory",
"itemset",
"landmarking",
"model-based",
"statistical"
]

streams = os.listdir('data/moa')
streams.remove('.DS_Store')
print(streams)

base_clfs = [
GaussianNB(),
KNeighborsClassifier(),
SVC(random_state=11313),
DecisionTreeClassifier(random_state=11313),
MLPClassifier(random_state=11313)
]

origial_datasets=len(streams)

n_splits=2
n_repeats=5

clf_res = np.zeros((len(measures), origial_datasets, n_splits*n_repeats, len(base_clfs)))
pbar = tqdm(total=len(measures)*origial_datasets*n_splits*n_repeats*len(base_clfs))

for f_id in range(len(streams)):
for m_id, m in enumerate(measures):
res = np.load('results/moa_%s_%i.npy' % (m, f_id))

p = np.random.permutation(res.shape[0])
res = res[p]

# print(res_rep.shape) # chunks, measures + label
X = res[:,:-1]
y = res[:,-1]

X[np.isnan(X)]=1
X[np.isinf(X)]=1

rskf = RepeatedStratifiedKFold(n_splits=n_splits, n_repeats=n_repeats, random_state=3242)
for fold, (train, test) in enumerate(rskf.split(X, y)):

for base_id, base_c in enumerate(base_clfs):
clf = clone(base_c)

pred = clf.fit(X[train], y[train]).predict(X[test])
acc = balanced_accuracy_score(y[test], pred)

clf_res[m_id, f_id, fold, base_id] = acc
pbar.update(1)

print(m, np.mean(clf_res[m_id, f_id], axis=0))

np.save('results/moa_clf.npy', clf_res)
57 changes: 57 additions & 0 deletions E_MOA_2P.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Plot E2 - Visualize classification results for MOA streams
"""
import numpy as np
import matplotlib.pyplot as plt
import os

np.random.seed(1233)

measures = ["clustering",
"complexity",
"concept",
"general",
"info-theory",
"itemset",
"landmarking",
"model-based",
"statistical"
]

streams = os.listdir('data/moa')
streams.remove('.DS_Store')
print(streams)

base_clfs = ['GNB', 'KNN', 'SVM', 'DT', 'MLP']

n_drift_types=3
stream_reps=5

res = np.load('results/moa_clf.npy') # measures, datasets, reps, folds, clfs

res_mean = np.mean(res, axis=2)
print(res_mean.shape)

fig, ax = plt.subplots(4, 3, figsize=(10,20), sharex=True, sharey=True)
ax=ax.ravel()
plt.suptitle('MOA', fontsize=18, y=0.99)

for dataset_id, dataset in enumerate(streams):

axx = ax[dataset_id]

r = res_mean[:,dataset_id]
axx.imshow(r, vmin=0.4, vmax=1., cmap='Blues')

for _a, __a in enumerate(measures):
for _b, __b in enumerate(base_clfs):
axx.text(_b, _a, "%.3f" % (r[_a, _b]) , va='center', ha='center', c='black' if r[_a, _b]<0.75 else 'white', fontsize=11)

axx.set_title(dataset.split('.')[0])
axx.set_xticks(np.arange(len(base_clfs)),base_clfs)
axx.set_yticks(np.arange(len(measures)),measures)


plt.tight_layout()
plt.savefig('foo.png')
plt.savefig('figures/fig_clf/MOA.png')
100,013 changes: 0 additions & 100,013 deletions data/moa/osd_s_hyp_r1_s_rbf_r1.arff

This file was deleted.

100,013 changes: 0 additions & 100,013 deletions data/moa/osd_s_hyp_r2_s_rbf_r2.arff

This file was deleted.

100,013 changes: 0 additions & 100,013 deletions data/moa/osd_s_hyp_r3_s_rbf_r3.arff

This file was deleted.

Binary file added figures/fig_clf/MOA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed figures/fig_moa/clustering_12.png
Binary file not shown.
Binary file removed figures/fig_moa/clustering_13.png
Binary file not shown.
Binary file removed figures/fig_moa/clustering_14.png
Binary file not shown.
Binary file modified figures/fig_moa/clustering_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/clustering_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/complexity_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/complexity_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/complexity_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/complexity_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed figures/fig_moa/complexity_12.png
Binary file not shown.
Binary file removed figures/fig_moa/complexity_13.png
Binary file not shown.
Binary file removed figures/fig_moa/complexity_14.png
Binary file not shown.
Binary file modified figures/fig_moa/complexity_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/complexity_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/fig_moa/complexity_4.png
Binary file modified figures/fig_moa/complexity_5.png
Binary file modified figures/fig_moa/complexity_6.png
Binary file modified figures/fig_moa/complexity_7.png
Binary file modified figures/fig_moa/complexity_8.png
Binary file modified figures/fig_moa/complexity_9.png
Binary file modified figures/fig_moa/concept_0.png
Binary file modified figures/fig_moa/concept_1.png
Binary file modified figures/fig_moa/concept_10.png
Binary file modified figures/fig_moa/concept_11.png
Binary file removed figures/fig_moa/concept_12.png
Diff not rendered.
Binary file removed figures/fig_moa/concept_13.png
Diff not rendered.
Binary file removed figures/fig_moa/concept_14.png
Diff not rendered.
Binary file modified figures/fig_moa/concept_2.png
Binary file modified figures/fig_moa/concept_3.png
Binary file modified figures/fig_moa/concept_4.png
Binary file modified figures/fig_moa/concept_5.png
Binary file modified figures/fig_moa/concept_6.png
Binary file modified figures/fig_moa/concept_7.png
Binary file modified figures/fig_moa/concept_8.png
Binary file modified figures/fig_moa/concept_9.png
Binary file modified figures/fig_moa/general_0.png
Binary file modified figures/fig_moa/general_10.png
Binary file modified figures/fig_moa/general_11.png
Binary file removed figures/fig_moa/general_12.png
Diff not rendered.
Binary file removed figures/fig_moa/general_13.png
Diff not rendered.
Binary file removed figures/fig_moa/general_14.png
Diff not rendered.
Binary file modified figures/fig_moa/general_3.png
Binary file modified figures/fig_moa/general_4.png
Binary file modified figures/fig_moa/general_5.png
Binary file modified figures/fig_moa/general_6.png
Binary file modified figures/fig_moa/general_7.png
Binary file modified figures/fig_moa/general_8.png
Binary file modified figures/fig_moa/general_9.png
Binary file modified figures/fig_moa/info-theory_0.png
Binary file modified figures/fig_moa/info-theory_1.png
Binary file modified figures/fig_moa/info-theory_10.png
Binary file modified figures/fig_moa/info-theory_11.png
Binary file removed figures/fig_moa/info-theory_12.png
Diff not rendered.
Binary file removed figures/fig_moa/info-theory_13.png
Diff not rendered.
Binary file removed figures/fig_moa/info-theory_14.png
Diff not rendered.
Binary file modified figures/fig_moa/info-theory_2.png
Binary file modified figures/fig_moa/info-theory_3.png
Binary file modified figures/fig_moa/info-theory_4.png
Binary file modified figures/fig_moa/info-theory_5.png
Binary file modified figures/fig_moa/info-theory_6.png
Binary file modified figures/fig_moa/info-theory_7.png
Binary file modified figures/fig_moa/info-theory_8.png
Binary file modified figures/fig_moa/info-theory_9.png
Binary file modified figures/fig_moa/itemset_0.png
Binary file modified figures/fig_moa/itemset_1.png
Binary file modified figures/fig_moa/itemset_10.png
Binary file modified figures/fig_moa/itemset_11.png
Binary file removed figures/fig_moa/itemset_12.png
Diff not rendered.
Binary file removed figures/fig_moa/itemset_13.png
Diff not rendered.
Binary file removed figures/fig_moa/itemset_14.png
Diff not rendered.
Binary file modified figures/fig_moa/itemset_2.png
Binary file modified figures/fig_moa/itemset_3.png
Binary file modified figures/fig_moa/itemset_4.png
Binary file modified figures/fig_moa/itemset_5.png
Binary file modified figures/fig_moa/itemset_6.png
Binary file modified figures/fig_moa/itemset_7.png
Binary file modified figures/fig_moa/itemset_8.png
Binary file modified figures/fig_moa/itemset_9.png
Binary file modified figures/fig_moa/landmarking_0.png
Binary file modified figures/fig_moa/landmarking_1.png
Binary file modified figures/fig_moa/landmarking_10.png
Binary file modified figures/fig_moa/landmarking_11.png
Binary file removed figures/fig_moa/landmarking_12.png
Diff not rendered.
Binary file removed figures/fig_moa/landmarking_13.png
Diff not rendered.
Binary file removed figures/fig_moa/landmarking_14.png
Diff not rendered.
Binary file modified figures/fig_moa/landmarking_2.png
Binary file modified figures/fig_moa/landmarking_3.png
Binary file modified figures/fig_moa/landmarking_4.png
Binary file modified figures/fig_moa/landmarking_5.png
Binary file modified figures/fig_moa/landmarking_6.png
Binary file modified figures/fig_moa/landmarking_7.png
Binary file modified figures/fig_moa/landmarking_8.png
Binary file modified figures/fig_moa/landmarking_9.png
Binary file modified figures/fig_moa/model-based_0.png
Binary file modified figures/fig_moa/model-based_1.png
Binary file modified figures/fig_moa/model-based_10.png
Binary file modified figures/fig_moa/model-based_11.png
Binary file removed figures/fig_moa/model-based_12.png
Diff not rendered.
Binary file removed figures/fig_moa/model-based_13.png
Diff not rendered.
Binary file removed figures/fig_moa/model-based_14.png
Diff not rendered.
Binary file modified figures/fig_moa/model-based_2.png
Binary file modified figures/fig_moa/model-based_3.png
Binary file modified figures/fig_moa/model-based_4.png
Binary file modified figures/fig_moa/model-based_5.png
Binary file modified figures/fig_moa/model-based_6.png
Binary file modified figures/fig_moa/model-based_7.png
Binary file modified figures/fig_moa/model-based_8.png
Binary file modified figures/fig_moa/model-based_9.png
Binary file modified figures/fig_moa/statistical_0.png
Binary file modified figures/fig_moa/statistical_1.png
Binary file modified figures/fig_moa/statistical_10.png
Binary file modified figures/fig_moa/statistical_11.png
Binary file removed figures/fig_moa/statistical_12.png
Diff not rendered.
Binary file removed figures/fig_moa/statistical_13.png
Diff not rendered.
Binary file removed figures/fig_moa/statistical_14.png
Diff not rendered.
Binary file modified figures/fig_moa/statistical_2.png
Binary file modified figures/fig_moa/statistical_3.png
Binary file modified figures/fig_moa/statistical_4.png
Binary file modified figures/fig_moa/statistical_5.png
Binary file modified figures/fig_moa/statistical_6.png
Binary file modified figures/fig_moa/statistical_7.png
Binary file modified figures/fig_moa/statistical_8.png
Binary file modified figures/fig_moa/statistical_9.png
Binary file modified foo.png
Binary file added results/moa_clf.npy
Binary file not shown.
Binary file modified results/moa_clustering_0.npy
Binary file not shown.
Binary file modified results/moa_clustering_1.npy
Binary file not shown.
Binary file modified results/moa_clustering_10.npy
Binary file not shown.
Binary file modified results/moa_clustering_11.npy
Binary file not shown.
Binary file modified results/moa_clustering_2.npy
Binary file not shown.
Binary file modified results/moa_clustering_3.npy
Binary file not shown.
Binary file modified results/moa_clustering_4.npy
Binary file not shown.
Binary file modified results/moa_clustering_5.npy
Binary file not shown.
Binary file modified results/moa_clustering_6.npy
Binary file not shown.
Binary file modified results/moa_clustering_7.npy
Binary file not shown.
Binary file modified results/moa_clustering_8.npy
Binary file not shown.
Binary file modified results/moa_clustering_9.npy
Binary file not shown.
Binary file modified results/moa_complexity_0.npy
Binary file not shown.
Binary file modified results/moa_complexity_1.npy
Binary file not shown.
Binary file modified results/moa_complexity_10.npy
Binary file not shown.
Binary file modified results/moa_complexity_11.npy
Binary file not shown.
Binary file modified results/moa_complexity_2.npy
Binary file not shown.
Binary file modified results/moa_complexity_3.npy
Binary file not shown.
Binary file modified results/moa_complexity_4.npy
Binary file not shown.
Binary file modified results/moa_complexity_5.npy
Binary file not shown.
Binary file modified results/moa_complexity_6.npy
Binary file not shown.
Binary file modified results/moa_complexity_7.npy
Binary file not shown.
Binary file modified results/moa_complexity_8.npy
Binary file not shown.
Binary file modified results/moa_complexity_9.npy
Binary file not shown.
Binary file modified results/moa_concept_10.npy
Binary file not shown.
Binary file modified results/moa_concept_11.npy
Binary file not shown.
Binary file modified results/moa_concept_6.npy
Binary file not shown.
Binary file modified results/moa_concept_7.npy
Binary file not shown.
Binary file modified results/moa_concept_8.npy
Binary file not shown.
Binary file modified results/moa_concept_9.npy
Binary file not shown.
Binary file modified results/moa_general_10.npy
Binary file not shown.
Binary file modified results/moa_general_11.npy
Binary file not shown.
Binary file modified results/moa_general_6.npy
Binary file not shown.
Binary file modified results/moa_general_7.npy
Binary file not shown.
Binary file modified results/moa_general_8.npy
Binary file not shown.
Binary file modified results/moa_general_9.npy
Binary file not shown.
Binary file modified results/moa_info-theory_10.npy
Binary file not shown.
Binary file modified results/moa_info-theory_11.npy
Binary file not shown.
Binary file modified results/moa_info-theory_3.npy
Binary file not shown.
Binary file modified results/moa_info-theory_4.npy
Binary file not shown.
Binary file modified results/moa_info-theory_5.npy
Binary file not shown.
Binary file modified results/moa_info-theory_6.npy
Binary file not shown.
Binary file modified results/moa_info-theory_7.npy
Binary file not shown.
Binary file modified results/moa_info-theory_8.npy
Binary file not shown.
Binary file modified results/moa_info-theory_9.npy
Binary file not shown.
Binary file modified results/moa_itemset_10.npy
Binary file not shown.
Binary file modified results/moa_itemset_11.npy
Binary file not shown.
Binary file modified results/moa_itemset_6.npy
Binary file not shown.
Binary file modified results/moa_itemset_7.npy
Binary file not shown.
Binary file modified results/moa_itemset_8.npy
Binary file not shown.
Binary file modified results/moa_itemset_9.npy
Binary file not shown.
Binary file modified results/moa_landmarking_0.npy
Binary file not shown.
Binary file modified results/moa_landmarking_1.npy
Binary file not shown.
Binary file modified results/moa_landmarking_10.npy
Binary file not shown.
Binary file modified results/moa_landmarking_11.npy
Binary file not shown.
Binary file modified results/moa_landmarking_2.npy
Binary file not shown.
Binary file modified results/moa_landmarking_3.npy
Binary file not shown.
Binary file modified results/moa_landmarking_4.npy
Binary file not shown.
Binary file modified results/moa_landmarking_5.npy
Binary file not shown.
Binary file modified results/moa_landmarking_6.npy
Binary file not shown.
Binary file modified results/moa_landmarking_7.npy
Binary file not shown.
Binary file modified results/moa_landmarking_8.npy
Binary file not shown.
Binary file modified results/moa_landmarking_9.npy
Binary file not shown.
Binary file modified results/moa_model-based_0.npy
Binary file not shown.
Binary file modified results/moa_model-based_1.npy
Binary file not shown.
Binary file modified results/moa_model-based_10.npy
Binary file not shown.
Binary file modified results/moa_model-based_11.npy
Binary file not shown.
Binary file modified results/moa_model-based_2.npy
Binary file not shown.
Binary file modified results/moa_model-based_3.npy
Binary file not shown.
Binary file modified results/moa_model-based_4.npy
Binary file not shown.
Binary file modified results/moa_model-based_5.npy
Binary file not shown.
Binary file modified results/moa_model-based_6.npy
Binary file not shown.
Binary file modified results/moa_model-based_7.npy
Binary file not shown.
Binary file modified results/moa_model-based_8.npy
Binary file not shown.
Binary file modified results/moa_model-based_9.npy
Binary file not shown.
Binary file modified results/moa_statistical_10.npy
Binary file not shown.
Binary file modified results/moa_statistical_11.npy
Binary file not shown.
Binary file modified results/moa_statistical_6.npy
Binary file not shown.
Binary file modified results/moa_statistical_7.npy
Binary file not shown.
Binary file modified results/moa_statistical_8.npy
Binary file not shown.
Binary file modified results/moa_statistical_9.npy
Binary file not shown.

0 comments on commit 53c7a3d

Please sign in to comment.