Skip to content

Instantly share code, notes, and snippets.

@Mehdi-Amine
Last active November 8, 2023 08:24
Show Gist options
  • Save Mehdi-Amine/2a57f9317068ba754dd1bba7b44ba94f to your computer and use it in GitHub Desktop.
Save Mehdi-Amine/2a57f9317068ba754dd1bba7b44ba94f to your computer and use it in GitHub Desktop.
generating and visualizing a dataset using Scikit-learn and the make_moons() function
# 1- Generating a dataset.
from sklearn.datasets import make_moons
# X are the generated instances, an array of shape (500,2).
# y are the labels of X, with values of either 0 or 1.
X, y = make_moons(n_samples=500, noise=0.3, random_state=42)
# 2- Visualizing the dataset.
from matplotlib import pyplot as plt
# When the label y is 0, the class is represented with a blue square.
# When the label y is 1, the class is represented with a green triangle.
plt.plot(X[:, 0][y==1], X[:, 1][y==1], "bs")
plt.plot(X[:, 0][y==0], X[:, 1][y==0], "g^")
# X contains two features, x1 and x2
plt.xlabel(r"$x_1$", fontsize=20)
plt.ylabel(r"$x_2$", fontsize=20)
# Simplifying the plot by removing the axis scales.
plt.xticks([])
plt.yticks([])
# Displaying the plot.
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment