Skip to content

Commit b673a26

Browse files
committed
Hierarchical clustering implementation started
1 parent 349fe93 commit b673a26

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

examples/keras_integration.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
from keras.datasets import mnist
99
from keras.models import Sequential
10-
from keras.layers import Dense, Dropout
10+
from keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense
1111
from keras.wrappers.scikit_learn import KerasClassifier
1212
from modAL.models import ActiveLearner
1313

@@ -19,11 +19,14 @@ def create_keras_model():
1919
Should be passed to KerasClassifier in the Keras scikit-learn API.
2020
"""
2121
model = Sequential()
22-
model.add(Dense(512, activation='relu', input_shape=(784, )))
23-
model.add(Dropout(0.2))
24-
model.add(Dense(512, activation='relu'))
25-
model.add(Dropout(0.2))
26-
model.add(Dense(10, activation='sigmoid'))
22+
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 1)))
23+
model.add(MaxPooling2D(pool_size=(2, 2)))
24+
model.add(Dropout(0.25))
25+
model.add(Flatten())
26+
model.add(Dense(128, activation='relu'))
27+
model.add(Dropout(0.5))
28+
model.add(Dense(10, activation='softmax'))
29+
2730
model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])
2831

2932
return model
@@ -41,8 +44,8 @@ def create_keras_model():
4144

4245
# read training data
4346
(X_train, y_train), (X_test, y_test) = mnist.load_data()
44-
X_train = X_train.reshape(60000, 784).astype('float32') / 255
45-
X_test = X_test.reshape(10000, 784).astype('float32') / 255
47+
X_train = X_train.reshape(60000, 28, 28, 1).astype('float32') / 255
48+
X_test = X_test.reshape(10000, 28, 28, 1).astype('float32') / 255
4649
y_train = keras.utils.to_categorical(y_train, 10)
4750
y_test = keras.utils.to_categorical(y_test, 10)
4851

modAL/cluster.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
========================================
3+
Cluster-based active learning algorithms
4+
========================================
5+
"""
6+
7+
import numpy as np
8+
from sklearn.cluster.hierarchical import AgglomerativeClustering, _hc_cut
9+
10+
11+
class HierarchicalClustering:
12+
def __init__(self, X, labels):
13+
self.labels = labels
14+
self.cluster = AgglomerativeClustering(n_clusters=2, compute_full_tree=True)
15+
self.cluster.fit(X)
16+
17+
def __call__(self, *args, **kwargs):
18+
pass
19+
20+
def compute_errors(self):
21+
pass

modAL/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
2-
Core models for active learning algorithms.
2+
==========================================
3+
Core models for active learning algorithms
4+
==========================================
35
"""
46

57
import abc

0 commit comments

Comments
 (0)