인공지능/Machine Learning

[Machine Learning] 분류 예측 Support Vector Machine (SVM)

건휘맨 2024. 4. 15. 17:52

SVC(Support Vector Classification)

 

# 변수에 저장하여 사용

>>> classifier = SVC(kernel='linear')
>>> classifier = SVC(kernel='rbf')

# 'linear', 'poly', 'rbf', 'sigmoid', 'precomputed' 호출 가능
# default = 'rbf'

 

from sklearn.svm import SVC

>>> classifier = SVC() # 디폴트 값 'rbf'
>>> classifier.fit(X_train, y_train)

>>> y_pred = classifier.predict(X_test)
>>> y_pred
array([0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1,
       1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0,
       1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1,
       0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0,
       1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0], dtype=int64)
       
from sklearn.metrics import confusion_matrix, accuracy_score

>>> confusion_matrix(y_test, y_pred)
array([[49,  9],
       [ 3, 39]], dtype=int64)
       
>>> accuracy_score(y_test, y_pred)
0.88