Skip to content

Instantly share code, notes, and snippets.

@neelabalan
Created November 30, 2023 13:25
Show Gist options
  • Save neelabalan/309f2669175c3490440af2758246333b to your computer and use it in GitHub Desktop.
Save neelabalan/309f2669175c3490440af2758246333b to your computer and use it in GitHub Desktop.
Post log transformation
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Generating a right-skewed data distribution
data = np.random.exponential(scale=2, size=1000)
# Performing log transformation
log_transformed_data = np.log(data + 1) # Adding 1 to avoid log(0) issue
# Plotting both distributions for comparison
plt.figure(figsize=(12, 6))
# Original data plot
plt.subplot(1, 2, 1)
sns.histplot(data, kde=True)
plt.title('Original Right-Skewed Data')
# Log-transformed data plot
plt.subplot(1, 2, 2)
sns.histplot(log_transformed_data, kde=True, color='orange')
plt.title('Log-Transformed Data')
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment