바뀜
→SVM 알고리즘
|
|
|
|
|}
{| class="wikitable"
!의도
!설명
!방법
|-
|훈련데이터와 테스트데이터 분리
|귀찮은 일을 모듈이 해준다.
|<syntaxhighlight lang="python">
from sklearn.model_selection import train_test_split
train_data, test_data, train_label, test_label = train_test_split(data, label)
</syntaxhighlight>
|-
|정답률 예측
|
|<syntaxhighlight lang="python">
right =0; total =0
for idx, answer in enumerate(label): # 레이블의 인덱스를 얻는다.
p = pre[idx] # 인덱스값에 해당하는 예측값.
if p = answer: right += 1 # 정답과 일치한다면 right에 하나 추가.
total += 1
print("정답률 : ", right/total)
</syntaxhighlight>간단하게 모듈을 사용할 수도 있다.<syntaxhighlight lang="python">
from sklearn import metrics # 추가로 가져온다.
score = metrics.accuracy_score(label, pre) # 레이블과 예측값을 넣는다.
print('정답률 : ', score)
</syntaxhighlight>
|}
|}
data.append(row[0], row[1]) # 판단의 기초가 되는 데이터리스트를 만든다.
data.append(row[0], row[1]) # 판단의 기초가 되는 데이터리스트를 만든다.
label.append(row[2]) # 판단의 결과를 모은다.
label.append(row[2]) # 판단의 결과를 모은다.
</syntaxhighlight>데이터프레임을 활용하는 경우<syntaxhighlight lang="python">
</syntaxhighlight>데이터프레임을 활용하는 경우.(열 이름을 사용해 분리하는 게 가장 간단하고 직관적이다.)<syntaxhighlight lang="python">
df = pd.DataFrame(data)
df = pd.DataFrame(data)
data = df.ix[, 0:1] # 모든 데이터의 0~1 인덱스에 해당하는 것을 데이터로.
data = df.ix[, 0:1] # 모든 데이터의 0~1 인덱스에 해당하는 것을 데이터로.
|얼마나 잘 맞았는지 검증해본다.
|얼마나 잘 맞았는지 검증해본다.
|<syntaxhighlight lang="python">
|<syntaxhighlight lang="python">
from sklearn import metrics # 추가로 가져온다.
from sklearn import metrics # 추가로 가져온다.