CancetDataset을 이용해서 복잡도와 일반화관계알아보기학부공부/빅데이터기술2019. 3. 28. 21:15
Table of Contents
반응형
코드를 통해서 알아본다 .
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
import sklearn.datasets
import scipy as sp
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import mglearn
cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target, stratify=cancer.target, random_state=66)
train_accuracy = []
test_accuracy = []
# 1에서 10까지 이웃을 적용
neighbors_settings = range(1, 11)
for n_neighbors in neighbors_settings:
# 모델 생성
clf = KNeighborsClassifier(n_neighbors=n_neighbors).fit(X_train, y_train)
# 훈련 세트 정확도 저장
train_accuracy.append(clf.score(X_train, y_train))
# 일반화 정확도 저장
test_accuracy.append(clf.score(X_test, y_test))
plt.plot(neighbors_settings, train_accuracy, label="training accuracy")
plt.plot(neighbors_settings, test_accuracy, label="test accuracy")
plt.ylabel("accuracy")
plt.xlabel("n_neighbors")
plt.legend()
plt.show()
반응형
'학부공부 > 빅데이터기술' 카테고리의 다른 글
지도학습..? (0) | 2019.04.02 |
---|---|
K-최근접 이웃 분류 (0) | 2019.03.28 |
Dataset들을 사용해 보자 (0) | 2019.03.28 |
분류 ( classification ) 와 회귀 ( regression ) (0) | 2019.03.26 |
Iris Dataset을 다뤄보자 . (0) | 2019.03.23 |
@IT grow. :: IT grow.
#IT #먹방 #전자기기 #일상
#개발 #일상