-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdat.py
More file actions
39 lines (35 loc) · 789 Bytes
/
dat.py
File metadata and controls
39 lines (35 loc) · 789 Bytes
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
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
#import training data from train.csv divide into x and y
def train_data():
a= pd.read_csv("train.csv")
data= np.array(a)
y=data[:,0]
x=data[:,1:]
y=np.reshape(y,(42000,1))
y_data=np.zeros((y.shape[0],10))
for i in xrange(42000):
ind=y[i]
y_data[i][ind]=1
return x,y_data
#import test data from test.csv
def test_data():
b= pd.read_csv("test.csv")
data= np.array(b)
return data
def image(x):
plt.imshow(x,cmap=plt.get_cmap('gray'))
plt.show()
#show the grayscale pixels
def show(x):
x=np.reshape(x,(28,28))
plt.imshow(x,cmap=plt.get_cmap('gray'))
plt.show()
#sigmoid function
def sigmoid(z):
return 1/(1+np.e**(-z))
#derivative sigmoid function
def der_sigmoid(z):
a=sigmoid(z)
return a*(1-a)