-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ca598f
commit 53c7a3d
Showing
222 changed files
with
135 additions
and
300,039 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.