Statistical distributions describe how feature values are distributed. In Machine Learning, synthetic distribution generation is vital for data augmentation and initial algorithm validation.
np.random.uniform).np.random.normal).import numpy as np
from typing import Tuple
def generate_synthetic_distributions(size: int = 1000) -> Tuple[np.ndarray, np.ndarray]:
# Reproducible seed
np.random.seed(42)
# Uniform distribution between 0.0 and 10.0
uniform_data = np.random.uniform(low=0.0, high=10.0, size=size)
# Normal distribution with mean=50.0 and std_dev=5.0
normal_data = np.random.normal(loc=50.0, scale=5.0, size=size)
return uniform_data, normal_data
if __name__ == "__main__":
u_data, n_data = generate_synthetic_distributions()
print("--- Uniform Distribution ---")
print(f" Min: {np.min(u_data):.2f}, Max: {np.max(u_data):.2f}, Mean: {np.mean(u_data):.2f}")
print("
--- Normal Distribution ---")
print(f" Mean: {np.mean(n_data):.2f} (Target ~50.0), Std: {np.std(n_data):.2f} (Target ~5.0)")
np.random.seed() or np.random.default_rng(seed) when generating synthetic datasets.rng = np.random.default_rng() in modern NumPy code instead of legacy np.random.Generate a 1D NumPy array of 100 values sampled from a normal distribution with mean 0 and standard deviation 1 using np.random.normal().
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With