Skip to content

Commit 61173fb

Browse files
update urls unsupervised
1 parent cd8a061 commit 61173fb

File tree

8 files changed

+20
-2
lines changed

8 files changed

+20
-2
lines changed

unsupervised_class/books.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://deeplearningcourses.com/c/cluster-analysis-unsupervised-machine-learning-python
12
# https://www.udemy.com/cluster-analysis-unsupervised-machine-learning-python
23
import networkx as nx
34
import nltk

unsupervised_class/choose_k.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://deeplearningcourses.com/c/cluster-analysis-unsupervised-machine-learning-python
12
# https://www.udemy.com/cluster-analysis-unsupervised-machine-learning-python
23
import numpy as np
34
import matplotlib.pyplot as plt

unsupervised_class/gmm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://deeplearningcourses.com/c/cluster-analysis-unsupervised-machine-learning-python
12
# https://www.udemy.com/cluster-analysis-unsupervised-machine-learning-python
23
import numpy as np
34
import matplotlib.pyplot as plt
@@ -29,6 +30,11 @@ def gmm(X, K, max_iter=20, smoothing=10e-3):
2930
for n in xrange(N):
3031
R[n,k] = weighted_pdfs[n,k] / weighted_pdfs[n,:].sum()
3132

33+
# a faster way to do step 1: "vectorization"
34+
# for k in xrange(K):
35+
# weighted_pdfs[:,k] = pi[k]*multivariate_normal.pdf(X, M[k], C[k])
36+
# R = weighted_pdfs / weighted_pdfs.sum(axis=1, keepdims=True)
37+
3238
# step 2: recalculate params
3339
for k in xrange(K):
3440
Nk = R[:,k].sum()

unsupervised_class/hcluster.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://deeplearningcourses.com/c/cluster-analysis-unsupervised-machine-learning-python
12
# https://www.udemy.com/cluster-analysis-unsupervised-machine-learning-python
23
import numpy as np
34
import matplotlib.pyplot as plt

unsupervised_class/kmeans.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://deeplearningcourses.com/c/cluster-analysis-unsupervised-machine-learning-python
12
# https://www.udemy.com/cluster-analysis-unsupervised-machine-learning-python
23
import numpy as np
34
import matplotlib.pyplot as plt
@@ -25,7 +26,8 @@ def cost(X, R, M):
2526
def plot_k_means(X, K, max_iter=20, beta=1.0, show_plots=True):
2627
N, D = X.shape
2728
M = np.zeros((K, D))
28-
R = np.zeros((N, K))
29+
# R = np.zeros((N, K))
30+
exponents = np.empty((N, K))
2931

3032
# initialize M to random
3133
for k in xrange(K):
@@ -37,7 +39,11 @@ def plot_k_means(X, K, max_iter=20, beta=1.0, show_plots=True):
3739
# is this inefficient?
3840
for k in xrange(K):
3941
for n in xrange(N):
40-
R[n,k] = np.exp(-beta*d(M[k], X[n])) / np.sum( np.exp(-beta*d(M[j], X[n])) for j in xrange(K) )
42+
# R[n,k] = np.exp(-beta*d(M[k], X[n])) / np.sum( np.exp(-beta*d(M[j], X[n])) for j in xrange(K) )
43+
exponents[n,k] = np.exp(-beta*d(M[k], X[n]))
44+
45+
R = exponents / exponents.sum(axis=1, keepdims=True)
46+
# assert(np.abs(R - R2).sum() < 10e-10)
4147

4248
# step 2: recalculate means
4349
for k in xrange(K):

unsupervised_class/kmeans_fail.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://deeplearningcourses.com/c/cluster-analysis-unsupervised-machine-learning-python
12
# https://www.udemy.com/cluster-analysis-unsupervised-machine-learning-python
23
import numpy as np
34
from kmeans import plot_k_means

unsupervised_class/kmeans_mnist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://deeplearningcourses.com/c/cluster-analysis-unsupervised-machine-learning-python
12
# https://www.udemy.com/cluster-analysis-unsupervised-machine-learning-python
23

34
# data is from https://www.kaggle.com/c/digit-recognizer

unsupervised_class/kmeans_visualize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://deeplearningcourses.com/c/cluster-analysis-unsupervised-machine-learning-python
12
# https://www.udemy.com/cluster-analysis-unsupervised-machine-learning-python
23
import numpy as np
34
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)