Skip to content

Commit f6b6768

Browse files
minor changes
1 parent 950f410 commit f6b6768

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

linear_regression_class/moore.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
non_decimal = re.compile(r'[^\d]+')
1616

1717
for line in open('moore.csv'):
18-
r = line.split('\t')
18+
r = line.split('\t')
1919

20-
x = int(non_decimal.sub('', r[2].split('[')[0]))
21-
y = int(non_decimal.sub('', r[1].split('[')[0]))
22-
X.append(x)
23-
Y.append(y)
20+
x = int(non_decimal.sub('', r[2].split('[')[0]))
21+
y = int(non_decimal.sub('', r[1].split('[')[0]))
22+
X.append(x)
23+
Y.append(y)
2424

2525

2626
X = np.array(X)

nlp_class/nb.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Naive Bayes spam detection for NLP class, which can be found at:
22
# https://www.udemy.com/data-science-natural-language-processing-in-python
3+
# dataset: https://archive.ics.uci.edu/ml/datasets/Spambase
34

45
# Author: http://lazyprogrammer.me
56

unsupervised_class/gmm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from scipy.stats import multivariate_normal
66

77

8-
def gmm(X, K, max_iter=20):
8+
def gmm(X, K, max_iter=20, smoothing=10e-3):
99
N, D = X.shape
1010
M = np.zeros((K, D))
1111
R = np.zeros((N, K))
@@ -34,7 +34,7 @@ def gmm(X, K, max_iter=20):
3434
Nk = R[:,k].sum()
3535
pi[k] = Nk / N
3636
M[k] = R[:,k].dot(X) / Nk
37-
C[k] = np.sum(R[n,k]*np.outer(X[n] - M[k], X[n] - M[k]) for n in xrange(N)) / Nk + np.eye(D)*0.001
37+
C[k] = np.sum(R[n,k]*np.outer(X[n] - M[k], X[n] - M[k]) for n in xrange(N)) / Nk + np.eye(D)*smoothing
3838

3939

4040
costs[i] = np.log(weighted_pdfs.sum(axis=1)).sum()
@@ -54,7 +54,7 @@ def gmm(X, K, max_iter=20):
5454
print "pi:", pi
5555
print "means:", M
5656
print "covariances:", C
57-
57+
return R
5858

5959

6060
def main():

0 commit comments

Comments
 (0)