Recipe: How to check models AUC score using cross validation in Python?
MODEL SELECTION MODEL ACCURACY

How to check models AUC score using cross validation in Python?

This recipe helps you check models AUC score using cross validation in Python
In [1]:
## How to check model's AUC score using cross validation in Python
def Snippet_136():
    print()
    print(format('How to check model\'s AUC score using cross validation in Python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    from sklearn.model_selection import cross_val_score
    from sklearn.tree import DecisionTreeClassifier
    from sklearn.datasets import make_classification

    # Generate features matrix and target vector
    X, y = make_classification(n_samples = 10000,
                               n_features = 3,
                               n_informative = 3,
                               n_redundant = 0,
                               n_classes = 2,
                               random_state = 42)

    # Create Decision Tree model
    dtree = DecisionTreeClassifier()

    # Cross-validate model using accuracy
    print(); print(cross_val_score(dtree, X, y, scoring="roc_auc", cv = 7))
    mean_score = cross_val_score(dtree, X, y, scoring="roc_auc", cv = 7).mean()
    std_score = cross_val_score(dtree, X, y, scoring="roc_auc", cv = 7).std()
    print(); print(mean_score)
    print(); print(std_score)

Snippet_136()
*********How to check model's AUC score using cross validation in Python**********

[0.92377622 0.91398601 0.93627451 0.92787115 0.93067227 0.92366947
 0.93207283]

0.927102449371357

0.006134475860963237


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from Wipro
1 developer from Amazon
1 developer from HvH
1 developer from American Express
1 developer from ICU Medical
1 developer from ANAC
1 developer from Vodafone