Python Tutorial: Introduction to model validation
Key Takeaways
The video tutorial covers model validation in Python using scikit-learn, including steps such as creating a model, fitting the model, generating predictions, and reviewing model accuracy. The tutorial uses the 538 ultimate Halloween candy power ranking dataset to demonstrate model validation techniques.
Full Transcript
hello my name is Casey Jones and welcome to this course on model validation let's get started so what is model validation well model validation consists of various steps and processes that ensure your model performs as expected on new data the most common way to do this is to test your models accuracy on data it has never seen before called a holdout set if your models accuracy is similar for the data it was trained on and the holdout data you can claim that your model is validated however model validation can also consist of choosing the right model the best parameters and even the best accuracy metric the ultimate goal of model validation is to end up with the best performing model possible that achieves high accuracy on new data before we begin exploring model validation let's review some basic modeling steps using scikit-learn modeling in Python follows a simple procedure regardless of the type of model you are constructing whether you are a seasoned scikit-learn veteran are new to building models with this module let's take a quick look at these steps first we create a model by specifying the model type and its parameters in this case we are creating a random forest regression model with random forests regressor second we fit the model using the dot fit method this method has two main arguments X an array of data used in the model as training data and Y an array of response values matching the size of the X array when dot fit is used the model parameters will be printed in the console to assess model accuracy we generate predictions for data using the dot predict method and lastly we look at the accuracy metrics here we are comparing the models predictions the variable predictions and the actual responses Y test future lessons and exercises will be devoted to accuracy metrics as they are a vital component to model validation for this current example though we are looking at the mean absolute error this function takes two arrays as arguments the true values y true and the predicted values y pred and returns the mean absolute error between them this process of generating a model fitting predicting and then reviewing model accuracy will be repeated throughout this course if you are unfamiliar with these steps you should consider taking the prerequisite courses they will go into more detail about using Python and performing these modeling steps throughout this course we will use 538 ultimate Halloween candy power ranking data sets several times this data set contains 85 different candies data on their various characteristics and a column specifying how often that candy selected in a head-to-head matchup with other candies this column is a win percentage and contains values between 0 and 100 model validations main goal is to ensure that a predictive model will perform as expected on new data obtaining predictions for training data or seen data and testing data or unseen data is coded in the same way and uses the dot predict method generally models perform a lot better on data they have seen before as unseen data may have features or characteristics that were not exposed in the model if your training and testing errors are vastly different it may be a sign that your model is over fitted we will use model validation to make sure we get the best testing error possible let's see why model validation is so important by looking at an example of training and testing act
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/model-validation-in-python at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Hello, my name is Kasey Jones - And welcome to this course on model validation. Let's get started!
So what is model validation?
Well, model validation consists of various steps and processes that ensure your model performs as expected on new data. The most common way to do this is to test your model's accuracy on data it has never seen before (called a holdout set). If your model's accuracy is similar for the data, it was trained on, and the holdout data, you can claim that your model is validated. However, model validation can also consist of choosing the right model, the best parameters, and even the best accuracy metric.
The ultimate goal of model validation is to end up with the best performing model possible, that achieves high accuracy on new data. Before we begin exploring model validation, let's review some basic modeling steps using scikit-learn.
Modeling in Python follows a simple procedure, regardless of the type of model you are constructing. Whether you are a seasoned scikit-learn veteran or new to building models with this module, let's take a quick look at these steps.
First, we create a model by specifying the model type and its parameters. In this case, we are creating a random forest regression model with RandomForestRegressor().
Second, we fit the model using the .fit() method. This method has two main arguments. X, an array of data used in the model as training data, and y, an array of response values matching the size of the X array. When .fit() is used, the model parameters will be printed in the console.
To assess model accuracy, we generate predictions for data using the .predict() method.
And lastly, we look at the accuracy metrics. Here we are comparing the model's predictions (the variable predictions) and the ac
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: ML Pipelines
View skill →
🎓
Tutor Explanation
DeepCamp AI