Skip to content

Commit b415c82

Browse files
committed
init
0 parents  commit b415c82

File tree

5 files changed

+2836
-0
lines changed

5 files changed

+2836
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ignore the results of running code 'results/'
2+
results/*/*
3+
results/*.csv
4+
!/results/exp1/results.csv
5+
6+
*.pyc
7+
8+
*.hdf5
9+
*.ipynb_checkpoints
10+
*.p
11+
*.h5
12+
*.HDF5
13+
__pycache__

Keras-DEC.ipynb

Lines changed: 2764 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# [How to do Unsupervised Clustering with Keras](https://www.dlology.com/blog/how-to-do-unsupervised-clustering-with-keras/) | DLology Blog
2+
3+
4+
## How to Run
5+
Require [Python 3.5+](https://www.python.org/ftp/python/3.6.4/python-3.6.4.exe) and [Jupyter notebook](https://jupyter.readthedocs.io/en/latest/install.html) installed
6+
### Clone or download this repo
7+
```
8+
git clone https://github.com/Tony607/Keras_Deep_Clustering
9+
```
10+
### Install required libraries
11+
`pip3 install -r requirements.txt`
12+
13+
14+
In the project start a command line run
15+
```
16+
jupyter notebook
17+
```
18+
In the opened browser window open
19+
```
20+
Keras-DEC.ipynb
21+
```
22+
If you want to skip the training, you can try the pre-trained weights from the releases, [results.zip](https://github.com/Tony607/Keras_Deep_Clustering/releases/download/V0.1/results.zip). Extract
23+
`results` folders to the root of the project directory.
24+
25+
Happy coding! Leave a comment if you have any question.

metrics.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import numpy as np
2+
from sklearn.metrics import normalized_mutual_info_score, adjusted_rand_score
3+
4+
nmi = normalized_mutual_info_score
5+
ari = adjusted_rand_score
6+
7+
8+
def acc(y_true, y_pred):
9+
"""
10+
Calculate clustering accuracy. Require scikit-learn installed
11+
12+
# Arguments
13+
y: true labels, numpy.array with shape `(n_samples,)`
14+
y_pred: predicted labels, numpy.array with shape `(n_samples,)`
15+
16+
# Return
17+
accuracy, in [0,1]
18+
"""
19+
y_true = y_true.astype(np.int64)
20+
assert y_pred.size == y_true.size
21+
D = max(y_pred.max(), y_true.max()) + 1
22+
w = np.zeros((D, D), dtype=np.int64)
23+
for i in range(y_pred.size):
24+
w[y_pred[i], y_true[i]] += 1
25+
from sklearn.utils.linear_assignment_ import linear_assignment
26+
ind = linear_assignment(w.max() - w)
27+
return sum([w[i, j] for i, j in ind]) * 1.0 / y_pred.size

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
numpy
2+
tensorflow
3+
keras
4+
scipy
5+
matplotlib
6+
sklearn
7+
seaborn

0 commit comments

Comments
 (0)