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

bro's coding

sklearn.model_selection.cross_val_score 본문

[AI]/python.sklearn

sklearn.model_selection.cross_val_score

givemebro 2020. 4. 24. 11:17
반응형

교차검증

- shuffle을 적용하지 않고, 분류의 경우 원본 비율을 유지(stratified)(옵션으로 바꿀 수 있음)

 

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris

 

iris=load_iris()

from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import cross_val_score

model=DecisionTreeClassifier(max_features=2)

scores=cross_val_score(model,iris.data,iris.target,cv=3)# cv =3(조각 수) default : 3
'''
cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
'''
display(scores,scores.mean())

 

array([0.98039216, 0.88235294, 0.9375    ])
0.9334150326797386

 

 

scores=cross_val_score(model,iris.data,iris.target,cv=10)# default : 3

display(scores,scores.mean())

 

array([1.        , 0.93333333, 1.        , 0.93333333, 0.86666667,
       0.86666667, 0.86666667, 1.        , 1.        , 1.        ])
0.9466666666666667

 

반응형
Comments