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

bro's coding

sklearn.cross_val_score.models 본문

[AI]/python.sklearn

sklearn.cross_val_score.models

givemebro 2020. 4. 24. 12:22
반응형
from sklearn.datasets import load_breast_cancer
cancer=load_breast_cancer()
score=[]
from sklearn.model_selection import cross_val_score

 

 

from sklearn.neighbors import KNeighborsClassifier

model=KNeighborsClassifier()
scores=cross_val_score(model,cancer.data,cancer.target)
score.append(scores.mean())

 

 

from sklearn.linear_model import LogisticRegression
model=LogisticRegression()
scores=cross_val_score(model,cancer.data,cancer.target)
score.append(scores.mean())

 

 

from sklearn.svm import SVC
from sklearn.preprocessing import StandardScaler
model=SVC()
# SVC는 normalization이 필요
ss=StandardScaler()
ss.fit(cancer.data)
X=ss.transform(cancer.data)

scores=cross_val_score(model,X,cancer.target)
score.append(scores.mean())

 

 

from sklearn.tree import DecisionTreeClassifier
model=DecisionTreeClassifier()
scores=cross_val_score(model,cancer.data,cancer.target)
score.append(scores.mean())

 

label=['KNeighborsClassifier','LogisticRegression','SVC','DecisionTreeClassifier']
plt.plot(score)
plt.xticks(range(4),label,rotation=60)
plt.hlines(np.mean(score),0,3,linestyles=':')

반응형
Comments