neural_network/generate_dataset.py

30 lines
943 B
Python
Raw Permalink Normal View History

2024-06-24 13:52:44 +00:00
import numpy as np
import matplotlib.pyplot as plt
# Parameters
num_points = 1000 # Number of data points
radius = 5 # Radius to separate the classes
# Generate random (x, y) coordinates
x = np.random.uniform(-10, 10, num_points)
y = np.random.uniform(-10, 10, num_points)
# Calculate distance from the origin
distance = np.sqrt(x**2 + y**2)
# Class labels: 0 for inside the radius, 1 for outside the radius
labels = (distance > radius).astype(int)
# Plot the dataset
plt.figure(figsize=(8, 8))
plt.scatter(x[labels == 0], y[labels == 0], color='blue', label='Class 0 (Inside radius)')
plt.scatter(x[labels == 1], y[labels == 1], color='red', label='Class 1 (Outside radius)')
plt.axhline(0, color='black',linewidth=0.5)
plt.axvline(0, color='black',linewidth=0.5)
plt.grid(color = 'gray', linestyle = '--', linewidth = 0.5)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Generated Dataset for Classification Task')
plt.legend()
plt.show()