La función make_moons — 3:40 min#
3:40 min | Ultima modificación: Septiembre 27, 2021 | YouTube
Esta función permite la creación de dos semicírculos concentricos con aspecto de luna, donde cada semicírculo representa una clase.
[1]:
import matplotlib.pyplot as plt
from sklearn.datasets import make_moons
X, y = make_moons(
# -------------------------------------------------------------------------
# If int, the total number of points generated. If two-element tuple,
# number of points in each of two moons.
n_samples=100,
# -------------------------------------------------------------------------
# Shuffle the samples.
shuffle=False,
# -------------------------------------------------------------------------
# Standard deviation of Gaussian noise added to the data.
noise=0.0,
# -------------------------------------------------------------------------
# Determines random number generation for dataset shuffling and noise. Pass
# an int for reproducible output across multiple function calls.
# creation.
random_state=12346,
)
plt.figure(figsize=(7, 7))
plt.scatter(
X[y == 0, 0],
X[y == 0, 1],
color="tab:red",
edgecolors="k",
s=120,
alpha=0.9,
)
plt.scatter(
X[y == 1, 0],
X[y == 1, 1],
color="tab:blue",
edgecolors="k",
s=120,
alpha=0.9,
)
plt.gca().spines["left"].set_color("gray")
plt.gca().spines["bottom"].set_color("gray")
plt.gca().spines["top"].set_visible(False)
plt.gca().spines["right"].set_visible(False)
plt.axis("equal")
plt.show()
[2]:
X, y = make_moons(
n_samples=100,
shuffle=False,
noise=0.1,
# -------------------------------------------------------------------------
# Determines random number generation for dataset shuffling and noise. Pass
# an int for reproducible output across multiple function calls.
# creation.
random_state=12346,
)
plt.figure(figsize=(7, 7))
plt.scatter(
X[y == 0, 0],
X[y == 0, 1],
color="tab:red",
edgecolors="k",
s=120,
alpha=0.9,
)
plt.scatter(
X[y == 1, 0],
X[y == 1, 1],
color="tab:blue",
edgecolors="k",
s=120,
alpha=0.9,
)
plt.gca().spines["left"].set_color("gray")
plt.gca().spines["bottom"].set_color("gray")
plt.gca().spines["top"].set_visible(False)
plt.gca().spines["right"].set_visible(False)
plt.axis("equal")
plt.show()