<jupyter_start><jupyter_text>Using your covariance matrix, Generate from multivariate Gaussian<jupyter_code>mvnorm = stats.multivariate_normal(mean=[0, 0], cov=[[1., 0.7], 
                                                     [0.7, 1.]])
# Generate random samples from multivariate normal with correlation .5
x = mvnorm.rvs(10000)
h = sns.jointplot(x[:, 0], x[:, 1], kind='kde', stat_func=None);
h.set_axis_labels('X1', 'X2', fontsize=16);<jupyter_output><empty_output><jupyter_text>Inverse transform U = norm.cdf(norm)D = D.inverse_cdf(U)https://en.wikipedia.org/wiki/Inverse_transform_sampling<jupyter_code>norm = stats.norm()
x_unif = norm.cdf(x)

h = sns.jointplot(x_unif[:, 0], x_unif[:, 1], kind='hex', stat_func=None)<jupyter_output><empty_output><jupyter_text>transform each marginal to desired distribution of that column        Sklar theorem  ,<jupyter_code>m1 = stats.gumbel_l()  # Age column
m2 = stats.beta(a=10, b=2)  # Speed column<jupyter_output><empty_output><jupyter_text>this is your synthetic data with desired distribution and covariance<jupyter_code>x1_trans = m1.ppf(x_unif[:, 0])
x2_trans = m2.ppf(x_unif[:, 1])


import pandas as pd

df = pd.DataFrame({'x1' : x1_trans, 'x2' : x2_trans})<jupyter_output><empty_output><jupyter_text>matches original covariance above<jupyter_code>print(df.corr().values)
print(df.head())

h = sns.jointplot(x1_trans, x2_trans, kind='kde', stat_func=None);
h.set_axis_labels('New_X1', 'New_X2',  fontsize=16);<jupyter_output><empty_output><jupyter_text>compare to same columns without correlation<jupyter_code>x1 = m1.rvs(10000)
x2 = m2.rvs(10000)

h = sns.jointplot(x1, x2, kind='kde', xlim=(-6, 2), ylim=(.6, 1.0), stat_func=None);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1530849825378347, 'fraction_numerical': 0.037252619324796274, 'mean_word_length': 5.903614457831325, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '208526', 'license': 'Apache-2.0', 'n_tokens_mistral': 707, 'n_tokens_neox': 666, 'n_words': 120, 'path': 'copulas/Generate data given covariance.ipynb', 'repo_name': 'sanjosh/machine_learning', 'size': '1718'}