How to check models Average precision score using cross validation in Python?
MODEL SELECTION

How to check models Average precision score using cross validation in Python?

How to check models Average precision score using cross validation in Python?

This recipe helps you check models Average precision score using cross validation in Python

0
In [1]:
## How to check model's Average precision score using cross validation in Python
def Snippet_137():
    print()
    print(format('How to check model\'s Average precision 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="average_precision", cv = 7))
    mean_score = cross_val_score(dtree, X, y, scoring="average_precision", cv = 7).mean()
    std_score = cross_val_score(dtree, X, y, scoring="average_precision", cv = 7).std()
    print(); print(mean_score)
    print(); print(std_score)

Snippet_137()
**How to check model's Average precision score using cross validation in Python***

[0.88845957 0.88047835 0.9132533  0.89760678 0.89968758 0.89812809
 0.88732474]

0.8953026160280041

0.0105346251221406

Relevant Projects

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Data Science Project-All State Insurance Claims Severity Prediction
Data science project in R to develop automated methods for predicting the cost and severity of insurance claims.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.