Random Sampling in Pandas | #23 of 53: The Complete Pandas Course

Опубликовано: 22 Март 2026
на канале: AiML Mastery Club
1,233
17

Course materials Github: https://github.com/machinelearningplu...

--------------------

Random Sampling is very important to learn as this is often used approach or technique when you're building machine learning models.

Let's imagine you have a large data set. And from that large data set, you want to randomly select a smaller proportion of data from that data set. This is what is called as random sampling, right? This is random sampling. But why is this useful? What are the different cases in which you would use a random sampling, let's imagine a scenario where you are building a machine learning model, you are going to build a machine learning model on our last data set.

Now, typically, you wouldn't build or train your model on the entire data set, what you would do is you will take a smaller sample of that data set run your various experiments on that smaller data set. Once everything is tuned and set up, you will build your machine learning model on the entire data set. Finally, right this is often used approach or technique when you're building machine learning models.

So this is used while we are building machine learning models. Second approaches second use cases, there are certain machine learning algorithm such as a random forest. It uses bootstrap sampling internally when it is actually training your model. This is another use case besides this bootstrap sampling can be used to compute confidence intervals also, right. Third one is random sampling is used during cross validation. That is, you have a data set.

From this data set, you randomly sample a set of observations say this is a random sample randomly picked a sample, you train your model on this data set, use the trained model and test its performance on another random sample of your original data set.

This is a technique called cross validation to validate the performance of your machine learning model. These are some of the use cases. Now implementing random sampling in Python is very easy, you have a function called sample inside your data frame sample method of your data frame, you can use this to create your random samples. let's implement this on property claims data set.

Let me know if you have any questions!

---------------------------------------------

If you enjoyed this video, be sure to throw it a like and make sure to subscribe to not miss any future videos!

Thanks for watching!