반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

머신러닝.Linear SVM(선형 서포트벡터머신) 기초 본문

[AI]/python.sklearn

머신러닝.Linear SVM(선형 서포트벡터머신) 기초

givemebro 2020. 4. 14. 11:00
반응형

구분선을 긋고 선과 가장 가까운 점들을 찾는다.

그 점을 support vector 라고 한다.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

 

# data 준비
from sklearn.datasets import load_iris

iris=load_iris()
from sklearn.model_selection import train_test_split

col1=0
col2=1
X=iris.data[:,[col1,col2]]
y=iris.target
y[y==2]=1

from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y)

 

# SVC 적용
from sklearn.svm import LinearSVC
model=LinearSVC(C=10000000)
model.fit(X_train,y_train)

 

# 시각화(train)
import mglearn
plt.figure(figsize=[10,10])
mglearn.plots.plot_2d_classification(model,X,cm='Reds',alpha=0.3)
mglearn.discrete_scatter(X_train[:,col1],X_train[:,col2],y_train,alpha=0.8)

# 시각화(train)
import mglearn
plt.figure(figsize=[10,10])
mglearn.plots.plot_2d_classification(model,X,cm='Reds',alpha=0.3)
mglearn.discrete_scatter(X_test[:,col1],X_test[:,col2],y_test,alpha=0.8)

반응형
Comments