forked from lazyprogrammer/machine_learning_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
39 lines (28 loc) · 1.01 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# https://deeplearningcourses.com/c/unsupervised-deep-learning-in-python
# https://www.udemy.com/unsupervised-deep-learning-in-python
from __future__ import print_function, division
from builtins import range
# Note: you may need to update your version of future
# sudo pip install -U future
import numpy as np
import pandas as pd
from sklearn.utils import shuffle
def relu(x):
return x * (x > 0)
def error_rate(p, t):
return np.mean(p != t)
def getKaggleMNIST():
# MNIST data:
# column 0 is labels
# column 1-785 is data, with values 0 .. 255
# total size of CSV: (42000, 1, 28, 28)
train = pd.read_csv('../large_files/train.csv').values.astype(np.float32)
train = shuffle(train)
Xtrain = train[:-1000,1:] / 255
Ytrain = train[:-1000,0].astype(np.int32)
Xtest = train[-1000:,1:] / 255
Ytest = train[-1000:,0].astype(np.int32)
return Xtrain, Ytrain, Xtest, Ytest
def init_weights(shape):
w = np.random.randn(*shape) / np.sqrt(sum(shape))
return w.astype(np.float32)