[ë¨¸ì‹ ëŸ¬ë‹ìŠ¤í„°ë””/2016] [ë¨¸ì‹ ëŸ¬ë‹ìŠ¤í„°ë””/2016/목차] == ë‚´ìš© == * SVM 실습 with [http://scikit-learn.org/stable/ sklearn] * skflow(tensorflowì˜ contib/learn으로 í¡ìˆ˜ë¨)ì„ ì‚¬ìš©í•˜ë ¤ 했으나 svm모듈 ë¶€ë¶„ì´ ìµœì‹ ì»¤ë°‹ì—ë§Œ í¬í•¨ë˜ì–´ 있어 sklearnì„ ì‚¬ìš©í•˜ê¸°ë¡œ 함 * sklearn ë²„ì „ì€ 0.17.1 설치 방법 {{{ $ sudo pip install sklearn }}} === 코드 === {{{ import sklearn from sklearn import svm #### SVC with rbf kernel # default is rbf kernel clf = svm.SVC() x_data = [[0,0], [0,1], [1,0], [1,1]] # linear ## And gate y_data = [0, 0, 0, 1] clf.fit(x_data, y_data) # SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, # decision_function_shape=None, degree=3, gamma='auto', kernel='rbf', # max_iter=-1, probability=False, random_state=None, shrinking=True, # tol=0.001, verbose=False) clf.predict(x_data) # array([0, 0, 0, 0]) # wrong ## Or gate y_data = [0, 1, 1, 1] clf.fit(x_data, y_data) clf.predict(x_data) # array([1, 1, 1, 1]) # non-linear ## Xor gate y_data = [0, 1, 1, 0] clf.fit(x_data, y_data) clf.predict(x_data) # array([0, 1, 1, 0]) # Correct answer #### SVC with Linear kernel clf = svm.SVC(kernel='linear') clf.fit(x_data, y_data) # SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, # decision_function_shape=None, degree=3, gamma='auto', kernel='linear', # max_iter=-1, probability=False, random_state=None, shrinking=True, # tol=0.001, verbose=False) clf.predict(x_data) # array([0, 0, 0, 0]) #### LinearSVC clf = svm.LinearSVC() clf.fit(x_data, y_data) # LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True, # intercept_scaling=1, loss='squared_hinge', max_iter=1000, # multi_class='ovr', penalty='l2', random_state=None, tol=0.0001, # verbose=0) clf.predict(x_data) # array([0, 0, 0, 1]) # Correct answer }}} * non-linear는 분류하지만 linear는 분류하지 못하는 SVC? * multi-classì—서 분류 ì‹œì— voterì˜ ê²°ê³¼ì— ë”°ë¼ ë¶„ë¥˜ë¨ * ê²°ê³¼ì— 0ì´ ë§Žìœ¼ë©´(And gate) ëª¨ë‘ 0ì´ ë˜ê³ {{{ y_data = [0, 0, 0, 1]ë©´ 결과가 [0, 0, 0, 0] }}} * 1ì´ ë” ë§Žìœ¼ë©´(Or gate) {{{ y_data = [0, 1, 1, 1]ë©´ 결과가 [1, 1, 1, 1] }}} * and gate는multi classê°€ 아님 == ë‹¤ìŒ ì‹œê°„ì—는 == == ë” ë³´ê¸° ==