Python Tutorial: Hyperparameter tuning in python | Intro
Key Takeaways
This video tutorial introduces hyperparameter tuning in Python using scikit-learn, covering the basics of parameters and hyperparameters in machine learning models, specifically logistic regression and random forest models.
Full Transcript
welcome to the first lecture of hyper parameter tuning in Python I am Alex a data scientist from Sydney Australia so why study this course today algorithms are getting more and more complex and so the number of hyper parameters to choose from increases it becomes increasingly important to learn how to efficiently find optimal combinations as this search will likely take up a large portion of your time often it is quite easy to simply run scikit-learn functions on the default settings or perhaps code from a tutorial or book without really digging under the hood however what lies underneath is a vital importance to good model building you may be surprised by what you find this course will use a data set about credit card defaults it contains a number of variables related to the demographics and financial history of a group of people the target column shows whether or not they defaulted on their next loan payment it has already been pre processed and split ready to model note that at times we will take smaller samples to ensure that we can run the code you can find out more about it at the link in the slides to understand hyper parameters let's first start with parameters what are parameters parameters are components of the final model that are learned through the modeling process crucially you do not set these you cannot set these the algorithm discovers them through undertaking it steps to make this concrete consider a simple logistic regression model we create the estimator and fit to the data with default settings since the logistic regression model is a linear model we will get beta coefficients on our variables these are found in the co F property of our logistic regression object however if we print these out we can see it is a bit messy let us clean this up by creating a list of original variable names zipping this up with the coefficients and formatting into a neat data frame for easy viewing we can now sort the data frame and print the top three results for brevity do you recall setting pay zero to have a coefficient of 0.0 0.1 I don't the coefficients are parameters because we did not set them ourselves and we'll learn during the modeling process in our data the pay variables relate to how many months people have previously delayed their payments we can see that having a high number of months of delayed payments makes someone more likely to default next month to know what parameters and algorithm will produce you need to know a bit about the algorithm itself and how it works and consult the psychic learn documentation to see where the parameter is stored in the returned object the parameters are found in the documentation for that particular algorithm under the attribute section not the parameters section so what are the parameters entry based model that do not have linear coefficients the parameters of this model are in the nodes of the trees used to build the model such as what feature was split on and at what value to demonstrate that has firstly built a random forest estimator and fit to our data setting the max depth to be quite low only for visualization purposes then we can pull out a single tree found in the random forest estimator estimators attribute to visualize for simplicity we will choose show the image but you can explore visualizing this yourself using the mention packages here we see a graph of the nodes including the variables and values used in the splits we can see that the very first split was on the variable pay for and it sent samples left or right depending if they had a value above or below one for this variable do you remember setting this decision I certainly don't so how do we pull out the splits we saw here visually in a programmatic way let's say the left second from top node the tree we pulled out is a psychic learn tree object so we can find the variable it's split on by indexing into the dot feature attribute of this tree and matching up without X train columns to get the name the level used to split on is then found in the dot threshold attribute and we can print this out let's do some exercises to further explore the parameters
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/ob... at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Welcome to the first lecture of Hyperparameter Tuning in Python. I am Alex, a Data Scientist from Sydney, Australia.
So why study this course? Today algorithms are getting more and more complex, and so the number of hyperparameters to choose from increases.
It becomes increasingly important to learn how to efficiently find optimal combinations, as this search will likely take up a large portion of your time.
Often it is quite easy to simply run Scikit Learn functions on the default settings or perhaps code from a tutorial or book without really digging under the hood. However, what lies underneath is of vital importance to good model building. You may be surprised what you find!
This course will use a dataset about credit card defaults.
It contains a number of variables related to the demographics and financial history of a group of people. The target column shows whether or not they defaulted on their next loan payment.
It has already been pre-processed and split ready to model. Note that at times we will take smaller samples to ensure we can run the code.
You can find out more about it at the link in the slides.
To understand hyperparameters, let's first start with parameters. What are parameters?
Parameters are components of the final model that are learned through the modeling process.
Crucially, you do not set these. You cannot set these.
The algorithm discovers them through undertaking its steps.
To make this concrete, consider a simple logistic regression model.
We create the estimator and fit to the data with default settings.
Since the logistic regression model is a linear model, we will get beta coefficients on our variables. These are found in the coef_ property of our logistic regression object.
However, if we print these out we can see it
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: LLM Foundations
View skill →
🎓
Tutor Explanation
DeepCamp AI