반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- broscoding
- 대이터
- vscode
- C언어
- html
- web 용어
- discrete_scatter
- paragraph
- mglearn
- inorder
- java역사
- pycharm
- 웹 용어
- KNeighborsClassifier
- Keras
- 자료구조
- web
- 머신러닝
- CES 2O21 참여
- CES 2O21 참가
- cudnn
- tensorflow
- 결합전문기관
- classification
- 데이터전문기관
- web 사진
- bccard
- 재귀함수
- postorder
- web 개발
Archives
- Today
- Total
bro's coding
sklearn.SVM. C and gamma 변화 관찰 본문
반응형
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_breast_cancer
cancer=load_breast_cancer()
col1=0
col2=5
X=cancer.data[:,[col1,col2]]
y=cancer.target
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y)
X_mean=X_train.mean(axis=0)
X_std=X_train.std(axis=0)
X_train_norm=(X_train-X_mean)/X_std
X_test_norm=(X_test-X_mean)/X_std
from sklearn.svm import SVC
model=SVC(C=1,gamma=1,probability=True)
model.fit(X_train_norm,y_train)
train_score=model.score(X_train_norm,y_train)
test_score=model.score(X_test_norm,y_test)
display(train_score,test_score)
Cs=[10**i for i in range(-3,3)]
gammas=[10**i for i in range(-3,3)]
s_train=[]
s_test=[]
for C in Cs:
s1=[]
s2=[]
for gamma in gammas:
model=SVC(C=C,gamma=gamma)
model.fit(X_train_norm,y_train)
pred_y=model.predict(X_test_norm)
s1.append(model.score(X_train_norm,y_train))
s2.append(model.score(X_test_norm,y_test))
s_train.append(s1)
s_test.append(s2)
fig=plt.figure(figsize=[12,8])
for i in range(len(Cs)):
plt.subplot(1,len(Cs),1+i)
plt.plot(s_train[i],'gs--',label='train')
plt.plot(s_test[i],'ro-',label='test')
plt.title('C=%f'%(Cs[i]))
plt.xticks(range(len(gammas)),gammas)
plt.ylim(0,1)
plt.xlabel('gamma')
plt.ylabel('score')
plt.legend(loc='lower right')
plt.imshow(s_test,vmin=0.5,vmax=1,origin='lower',cmap='Reds')
plt.xticks(range(len(gammas)),gammas)
plt.yticks(range(len(Cs)),Cs)
plt.ylabel('C')
plt.xlabel('gamma')
plt.colorbar()
반응형
'[AI] > python.sklearn' 카테고리의 다른 글
sklearn.non-linear regression(비선형회귀) (0) | 2020.04.19 |
---|---|
sklearn.linear_model.Ridge.alpha에 따른 회귀선 변화 관찰 (0) | 2020.04.19 |
sklearn.linear_model.Lasso.alpha값에 따른 score변화 관찰 (0) | 2020.04.19 |
sklearn.Compare Ridge and Rasso (0) | 2020.04.17 |
sklearn.svm.SVC.decision bounds (0) | 2020.04.17 |
sklearn.svm.SVC and normalization(breast cancer) (0) | 2020.04.16 |
sklearn.svm.SVC(kernel 기법) (0) | 2020.04.16 |
sklearn.svm.LinearSVC.kernel 기법(타원형 데이터) (0) | 2020.04.16 |
Comments