In [1]:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
In [2]:
%matplotlib inline
In [3]:
from tensorflow.examples.tutorials.mnist import input_data
In [4]:
mnist = input_data.read_data_sets('/Users/jaegyuhan/PythonEx_1/mnist_data', one_hot=True)
In [5]:
type(mnist)
Out[5]:
In [6]:
type(mnist.train.images), type(mnist.train.images)
Out[6]:
In [7]:
print(mnist.train.images.shape)
In [8]:
print(mnist.train.labels.shape) #ont hot 인코딩이라서 10개이다. 0~9 중 해당 숫자만 1이고 나머지는 0으로 표기
In [9]:
print(mnist.train.labels[0:2])
In [10]:
np.argmax(mnist.train.labels[0:2], axis=1)
Out[10]:
In [11]:
n = np.array([[0,0,1],
[0,1,0]])
In [12]:
np.argmax(n, axis=1)
Out[12]:
In [13]:
y_train_labels = np.argmax(mnist.train.labels, axis=1)
In [14]:
X_train, Y_train = mnist.train.images, mnist.train.labels
In [15]:
X_test, Y_test = mnist.test.images, mnist.test.labels
In [37]:
len(X_test[0])
Out[37]:
In [38]:
Y_test[0]
Out[38]:
In [16]:
print(len(X_train))
print(np.bincount(np.argmax(Y_train, axis=1)))
In [17]:
fig, axes = plt.subplots(1, 8, figsize=(12,2), subplot_kw={'xticks':[], 'yticks':[]})
for i, ax in enumerate(axes.ravel()):
img = X_train[i+5000].reshape(28,28)
label = np.argmax(Y_train[i+5000])
ax.imshow(img)
ax.set_title('label : {}'.format(label))
plt.show()
In [18]:
X_train[0, 350:400]
Out[18]:
In [19]:
X_train
Out[19]:
In [20]:
X_train[0:2]
Out[20]:
In [21]:
X_train[0:2]
Out[21]:
In [22]:
X_train[1:3]
Out[22]:
In [23]:
n = np.array([[1,2,3],[4,5,6]])
In [24]:
n
Out[24]:
In [25]:
n[1:2, 1:2] #2차원 행렬중 행은 1행에서 2행미만 즉 1번인덱스 행 , 열도 1열이상 2열 미만 즉 1번인텍스 열 결과는 아래!
Out[25]:
In [26]:
n[0,1] #2차원 행렬중 행은 꼭찝어 0번 인덱스 행, 열은 꼭찝어 1번 인덱스 행
Out[26]:
In [27]:
Y_train[1]
Out[27]:
In [28]:
plt.imshow(X_train[1].reshape(28,28))
plt.show()
In [29]:
X_train[1].reshape(28,28)[0:2]
Out[29]:
In [30]:
len(X_train)
Out[30]:
In [31]:
len(Y_train)
Out[31]:
In [150]:
from sklearn.svm import SVC
In [151]:
Y_train_label = np.argmax(Y_train, axis=1)
In [ ]:
svc = SVC(kernel='rbf')
%timeit svc.fit(X_train, Y_train_label)
In [33]:
tf.cast(True, dtype=tf.float32)
Out[33]:
In [34]:
tf.cast(False, dtype=tf.float32)
Out[34]:
In [ ]: