VOOZH about

URL: https://www.geeksforgeeks.org/machine-learning/python-generate-test-datasets-for-machine-learning/

⇱ Generate Test Datasets for Machine learning - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Generate Test Datasets for Machine learning

Last Updated : 12 Jul, 2025

Whenever we think of Machine Learning, the first thing that comes to our mind is a dataset. While there are many datasets that you can find on websites such as Kaggle, sometimes it is useful to extract data on your own and generate your own dataset. Generating your own dataset gives you more control over the data and allows you to train your machine-learning model.  In this article, we will generate random datasets using sklearn.datasets library in Python.

Generate test datasets for Classification:

Binary Classification

Example 1: The 2d binary classification data generated by make_circles() have a spherical decision boundary.

Output:

👁 make_circles() - Geeksforgeeks
make_circles()

Example 2: Two interlocking half circles represent the 2d binary classification data produced by the make_moons() function.

Output:

👁 make_moons() -Geeksforgeeks
make_moons()

Multi-Class Classification

Example 1: Data generated by the function make_blobs() are blobs that can be utilized for clustering.

Output:

👁 make_blobs() - Geeksforgeeks
make_blobs()

Example 2: To generate data by the function make_classification() need to balance between n_informative, n_redundant and n_classes attributes X[:, :n_informative + n_redundant + n_repeated]

Output:

👁 make_classification() - Geeksforgeeks
make_classification()

Example 3:A random multi-label classification data is created by the function make make_multilabel_classification() 

Output:

 X1 X2 Label1 Label2
0 14.0 34.0 0 1
1 30.0 22.0 1 1
2 29.0 19.0 1 1
3 21.0 19.0 1 1
4 16.0 32.0 0 1
👁 make_multilabel_classification() - Geeksforgeeks
make_multilabel_classification()

Generate test datasets for Regression:

Example 1:  Generate a 1-dimensional feature and target for linear regression using make_regression

Output:

👁 make_regression() -Geeksforgeeks
make_regression()

Example 2:  Multilabel feature using make_sparse_uncorrelated()

Output:

👁 make_sparse_uncorrelated()-Geeksforgeeks
make_sparse_uncorrelated()

Example: 3  Multilabel feature using make_friedman2()

Output:

👁 make_friedman2() - Geeksforgeeks
make_friedman2()


 

Comment