Python | Create Test DataSets using Sklearn
Python’s Sklearn library provides a great sample dataset generator which will help you to create your own custom dataset. It’s fast and very easy to use. Following are the types of samples it provides.
For all the above methods you need to import sklearn.datasets.samples_generator.
Attention reader! Don’t stop learning now. Get hold of all the important Machine Learning Concepts with the Machine Learning Foundation Course at a student-friendly price and become industry ready.
Python3
# importing librariesfrom sklearn.datasets import make_blobs# matplotlib for plotingfrom matplotlib import pyplot as pltfrom matplotlib import style |
sklearn.datasets.make_blobs
Python3
# Creating Test DataSets using sklearn.datasets.make_blobsfrom sklearn.datasets import make_blobsfrom matplotlib import pyplot as pltfrom matplotlib import stylestyle.use("fivethirtyeight")X, y = make_blobs(n_samples = 100, centers = 3, cluster_std = 1, n_features = 2)plt.scatter(X[:, 0], X[:, 1], s = 40, color = 'g')plt.xlabel("X")plt.ylabel("Y")plt.show()plt.clf() |
Output:

make_blobs with 3 centers
sklearn.datasets.make_moon
Python3
# Creating Test DataSets using sklearn.datasets.make_moonfrom sklearn.datasets import make_moonfrom matplotlib import pyplot as pltfrom matplotlib import styleX, y = make_moons(n_samples = 1000, noise = 0.1)plt.scatter(X[:, 0], X[:, 1], s = 40, color ='g')plt.xlabel("X")plt.ylabel("Y")plt.show()plt.clf() |
Output:

make_moons with 1000 data points
sklearn.datasets.make_circle
Python3
# Creating Test DataSets using sklearn.datasets.make_circlesfrom sklearn.datasets import make_circlesfrom matplotlib import pyplot as pltfrom matplotlib import stylestyle.use("fivethirtyeight")X, y = make_circles(n_samples = 100, noise = 0.02)plt.scatter(X[:, 0], X[:, 1], s = 40, color ='g')plt.xlabel("X")plt.ylabel("Y")plt.show()plt.clf() |
Output:

make _circle with 100 data points

