0% found this document useful (0 votes)
6 views

Intro

Uploaded by

mulwad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Intro

Uploaded by

mulwad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [1]:

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm, pearsonr

np.random.seed(0)
x, y = np.random.normal(0, 1, 1000), 0.5 * np.random.normal(0, 1, 1000) + np.random.norma
corr_coeff, _ = pearsonr(x, y)

fig, axs = plt.subplots(1, 2, figsize=(14, 6))


for data, color, ax in zip([x, y], ['g', 'b'], axs):
ax.hist(data, bins=30, density=True, alpha=0.6, color=color)
x_range = np.linspace(*ax.set_xlim(), 100)
ax.plot(x_range, norm.pdf(x_range, np.mean(data), np.std(data)), 'k', linewidth=2)
ax.set_title(f"mean = {np.mean(data):.2f}, std = {np.std(data):.2f}")
plt.show()

plt.scatter(x, y, alpha=0.5)
plt.title(f'Correlation Coefficient: {corr_coeff:.2f}')
plt.xlabel('x')
plt.ylabel('y')
plt.grid(True)
plt.show()
In [ ]:

In [ ]:

You might also like