๋จธ์‹ ๋Ÿฌ๋‹ ๊ธฐ๋ฒ• ์ค‘์˜ ํ•˜๋‚˜์ธ DBN(Deep Belief Network)์„
์ด์šฉํ•˜๋ฉด ์ด๋ฏธ์ง€๋ฅผ ํ•™์Šต์‹œํ‚ค๊ณ  ์ƒˆ๋กœ ๋“ค์–ด์˜ค๋Š” ์ด๋ฏธ์ง€์—

์ด๋ฅผ ์ ์šฉํ•˜์—ฌ ๊ฒฐ๊ณผ์— ๋Œ€ํ•œ ํ™•๋ฅ ์„ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

ํด๋ผ์šฐ๋“œ ๋ถ„์„ ํ™˜๊ฒฝ์ธ IBM Data Science Experience ๋‚ด์—์„œ
ํŒŒ์ด์ฌ์˜ nolearn ํŒจํ‚ค์ง€๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ˆซ์ž ์ด๋ฏธ์ง€๋ฅผ ํ•™์Šต์‹œํ‚ค๊ณ  ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๊ฐ€ ์–ด๋–ค ์ˆซ์ž์˜ ํ™•๋ฅ ์ด
๋†’์€์ง€

ํ™•์ธํ•ด ๋ณด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

 

์šฐ์„  http://datascience.ibm.com/ ๋กœ๊ทธ์ธ ํ”„๋กœ์ ํŠธ
๋‚ด์— Notebook ์ƒ์„ฑ. ์–ธ์–ด๋Š” Python 2์„ ์„ ํƒ

 

# ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋กœ๋“œํ•˜๊ธฐ

!pip install –user nolearn

import warnings

warnings.filterwarnings("ignore")

from sklearn.cross_validation import
train_test_split

from sklearn.metrics import
classification_report

from sklearn import datasets

from nolearn.dbn import DBN

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

%matplotlib inline

 

# ์ˆ˜๊ธฐ๋กœ ๋œ ์ˆซ์ž ์ด๋ฏธ์ง€ ๋กœ๋“œ

from tensorflow.examples.tutorials.mnist
import input_data

mnist =
input_data.read_data_sets("MNIST_data/")

 

mnist_images = mnist.train.images

mnist_labels = mnist.train.labels

 

# ์ด๋ฏธ์ง€๋ฅผ ํŠธ๋ ˆ์ด๋‹, ํ…Œ์ŠคํŠธ
์…‹์œผ๋กœ ๋ถ„๋ฆฌ. ๊ฒฐ๊ณผ ํ™•์ธ

trX, teX, trY, teY = train_test_split(mnist_images,
mnist_labels.astype("int0"), test_size = 0.33)

print "Number of images for
training:", trX.shape[0]

print "Number of images used for
testing:", trY.shape[0]

pix = int(np.sqrt(teX.shape[1]))

print "Each image is:", pix,
"by", pix, "pixels"

 

# ์ด๋ฏธ์ง€ ํ•™์Šต ํ›ˆ๋ จ

dbn = DBN(

    [trX.shape[1], 300, 10],

    learn_rates = 0.3,

    learn_rate_decays = 0.9,

    epochs = 10,

    verbose = 1) # set
verbose to 0 for not printing output

dbn.fit(trX, trY)

 

 

# ๊ฐ ์ˆซ์ž์˜ ํ’ˆ์งˆ ์˜ˆ์ธก ํ‰๊ฐ€, ์‹ค์ œ
์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ๊ฒฐ๊ณผ ํ™•์ธ

preds = dbn.predict(teX)

print classification_report(teY, preds)

 

def randIm():

    i =
np.random.choice(np.arange(0, len(teY)), size = (1,))

    pred =
dbn.predict(np.atleast_2d(teX[i]))

    image = (teX[i] *
255).reshape((28, 28)).astype("uint8")

    # show the prediction

    print "Actual digit
is", teY[i][0], "predicted", pred[0]

    imgplot =
plt.imshow(image)

   
imgplot.set_cmap(‘gray’)  

 

randIm()

randIm()

 

 

 

ํ† ๋ก  ์ฐธ๊ฐ€

์ด๋ฉ”์ผ์€ ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ์ž…๋ ฅ์ฐฝ์€ * ๋กœ ํ‘œ์‹œ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค