Scikit-learn 모듈
LinearSVC
from sklearn.svm import LinearSVC
from sklearn.metrics import accuracy_score
LinearSVC()
svc.fit(학습시킬 실행값, 학습시킬 결과값)
# 학습 데이터 준비
learn_data = [[0,0], [1,0], [0,1], [1,1]]
learn_label = [0,0,0,1]
# 학습
svc.fit(learn_data, learn_label)
svc.predict(테스트값)
test_label = svc.predict(test_data)
# [0 0 0 1]
accuracy_score(체크할 값, 결과값)
print('정답률: ', accuracy_score([0,0,0,1], test_label))
# 정답률: 1.0
Iris DataSet
from sklearn.datasets import load_iris
import pandas as pd
iris = load_iris()
train_test_split()
전체 데이터셋 배열을 받아서 랜덤하게 test/train 데이터 셋으로 분리해주는 함수
from sklearn.model_selection import train_test_split
# 학습용독립변수, 학습용종속변수, 검증용독립변수, 검증용종속변수 = train_test_split(독립변수, 종속변수, test_size=검증용데이터사이즈,random_state=랜덤시드)
X_train, X_test, y_train, y_test = train_test_split(df_iris.drop('target', 1), df_iris['target'], test_size=0.2, random_state=10)
import seaborn as sns
sns.countplot(y_train)
X_train, X_test, y_train, y_test = train_test_split(df_iris.drop('target', 1), df_iris['target'], test_size=0.2, random_state=10, stratify=df_iris['target'])