2장은 분류법에 대한 소개 정도를 하는 챕터이다.


(1) 홀드 아웃 : 하나는 모델을 훈련시키고 다른 하나는 테스트에 사용

(2) 교차 검증(cross-validation) : 

- 단일 잔류 : 극단적인 교차 검증의 형태로 하나의 예를 제외한 모든 데이터로 모델을 학습하고, 이 모델이 남은 하나의 예를 잘 분류하는지 보는 것. 100배 더 가중된 일을 해야함

- x중첩(x - fold) 교차 검증 : x는 작은 숫자로 예를 들면 5 정도이다. 5개의 중첩 교차 검증을 수행하고자 전체 데이터를 다섯 그룹으로 나눈다. 즉 전체 데이터의 20% 정도를 남겨둔다.

(3) 최근접 이웃 분류

- 먼저 데이터 셋을 나누어 두고 새로운 데이터가 들어오면 이 데이터와 가장 가까운 데이터셋 몇개를 찾아 대충 어느 범주에 들어 있는지 찾는다..

- k최근접 이웃 분류 : 가장 가까운 하나의 점이 아닌 k개 만큼 가까운 점들을 고려함. 일반적으로 k는 작지만 데이터셋이 매우 크다면 큰 숫자로 할 수도 있다.



Posted by 공놀이나하여보세
,

아래에 자세한 코드가 있음

출처 : http://stackoverflow.com/questions/25351488/intermittent-python-thread-error-main-thread-is-not-in-main-loop


from Tkinter import *
import tkFont
import os
import glob
import time
import threading
import Image 
import Queue


def update_temp(queue):
    """ Read the temp data. This runs in a background thread. """
    while True:
        #   28-000005c6ba08
        i = "28-000005c6ba08"
        base_dir = '/sys/bus/w1/devices/'
        device_folder = glob.glob(base_dir + i)[0]
        device_file = device_folder + '/w1_slave'

        tempread=round(read_temp(),1)

        # Pass the temp back to the main thread.
        queue.put(tempread)
        time.sleep(5)

class Gui(object):
    def __init__(self, queue):
        self.queue = queue

        #Make the window
        self.root = Tk() 
        self.root.wm_title("Home Management System")
        self.root.minsize(1440,1000)

        self.equipTemp = StringVar()   
        self.equipTemp1 = StringVar()
        self.equipTemp2 = StringVar()       

        self.customFont = tkFont.Font(family="Helvetica", size=16)

        #   1st floor Image
        img = Image.open("HOUSE-PLANS-01.png") 
        photo = ImageTk.PhotoImage(img)

        Label1=Label(self.root, image=photo)
        Label1.place(x=100, y=100)

        #   2nd floor
        img2 = Image.open("HOUSE-PLANS-02.png")
        photo2 = ImageTk.PhotoImage(img2)

        Label1=Label(self.root, image=photo2)
        Label1.place(x=600, y=100)

        #   Basement image
        img3 = Image.open("HOUSE-PLANS-03.png")
        photo3 = ImageTk.PhotoImage(img3)

        Label1=Label(self.root, image=photo3)
        Label1.place(x=100, y=500)

        #   Attic Image
        img4 = Image.open("HOUSE-PLANS-04.png")
        photo4 = ImageTk.PhotoImage(img4)

        Label1=Label(self.root, image=photo4)
        Label1.place(x=600, y=500)

        #   House Isometric Image
        img5 = Image.open("house-iso.png")
        photo5 = ImageTk.PhotoImage(img5)

        Label1=Label(self.root, image=photo5)
        Label1.place(x=1080, y=130)

        #Garage Temp Label
        Label2=Label(self.root, textvariable=self.equipTemp, width=6, justify=RIGHT, font=self.customFont)
        Label2.place(x=315, y=265)

        print "start monitoring and updating the GUI"

        # Schedule read_queue to run in the main thread in one second.
        self.root.after(1000, self.read_queue)

    def read_queue(self):
        """ Check for updated temp data"""
        try:
            temp = self.queue.get_nowait()
            self.equipTemp.set(temp)
        except Queue.Empty:
            # It's ok if there's no data to read.
            # We'll just check again later.
            pass
        # Schedule read_queue again in one second.
        self.root.after(1000, self.read_queue)

if __name__ == "__main__":
    queue = Queue.Queue()
    # Start background thread to get temp data
    t = threading.Thread(target=update_temp, args=(queue,))
    t.start()
    print "starting app"
    # Build GUI object
    gui = Gui(queue)
    # Start mainloop
    gui.root.mainloop()


Posted by 공놀이나하여보세
,

제이펍의 '라즈베리파이 시작하기' 라는 책에 라즈베리파이로 아두이노 구동을 위한 내용이 잘 정리 되어 있습니다.


책의 내용을 다 옮기긴 어렵겠지만 기본적인 것에 대해 말씀드려볼까 합니다.

저는 처음에 둘을 연결하려면 뭔가 선을 따줘야 할거라고 생각했습니다.

물론 제대로 된 통신을 하려면 SPI통신을 이용해야할 거라고 생각합니다.(아직 해보진 않았습니다만..)

하지만, 책을 보니 그냥 시리얼 통신을 이용했더군요.

게다가 시리얼 통신을 위해서 점퍼선을 연결할 필요도 없습니다.

그냥 USB케이블 하나를 연결하면 됩니다.



저는 귀찮아서 샤오미 배터리를 전원으로 쓰고 usb wifi동글로 무선 연결을 해두고 맥북에서 원격 접속으로 작업을 합니다.

여튼 이렇게 선 하나만 연결합니다.



sudo apt-get install arduino 

arduino IDE를 다운 받습니다.

마지막으로 IDE에 uart 출력을 c로 코딩합니다.

-> 버튼을 누르면 알아서 컴파일이 되고 아두이노로 다운로드하고 실행이 됩니다.


라즈베리파이에서 serial 입력을 받아 print하는 코드를 python으로 짭니다.

그리고 실행하면 위의 사진 처럼 아두이노가 보내는 데이터를 출력해줍니다.


간단하네요 ㅋㅋ


자세한 내용은 책을 참조하시거나 인터넷을 뒤져 보시길..


Posted by 공놀이나하여보세
,