-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpart2_mnist_data_set.py
More file actions
82 lines (41 loc) · 1.23 KB
/
Copy pathpart2_mnist_data_set.py
File metadata and controls
82 lines (41 loc) · 1.23 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# coding: utf-8
# In[2]:
# python notebook for Make Your Own Neural Network
# working with the MNIST data set
#
# (c) Tariq Rashid, 2016
# license is GPLv2
# In[3]:
import numpy
import matplotlib.pyplot
get_ipython().run_line_magic('matplotlib', 'inline')
# In[4]:
# open the CSV file and read its contents into a list
data_file = open("mnist_dataset/mnist_train_100.csv", 'r')
data_list = data_file.readlines()
data_file.close()
# In[5]:
# check the number of data records (examples)
len(data_list)
# In[6]:
# show a dataset record
# the first number is the label, the rest are pixel colour values (greyscale 0-255)
data_list[1]
# In[7]:
# take the data from a record, rearrange it into a 28*28 array and plot it as an image
all_values = data_list[1].split(',')
image_array = numpy.asfarray(all_values[1:]).reshape((28,28))
matplotlib.pyplot.imshow(image_array, cmap='Greys', interpolation='None')
# In[8]:
# scale input to range 0.01 to 1.00
scaled_input = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01
print(scaled_input)
# In[12]:
#output nodes is 10 (example)
onodes = 10
targets = numpy.zeros(onodes) + 0.01
targets[int(all_values[0])] = 0.99
# In[13]:
print(targets)
# In[ ]: