I would like to generate a training and test set for the binary classification problem. I want the instances to be generated from a multivariate normal distribution and have 5 features. Can someone explain how to do this in python?

  • $\begingroup$ Hi @Marni. This question seems like homework. What have you tried up to now? $\endgroup$ – noe May 8 at 18:57
  • $\begingroup$ this is not my homework, i do it for myself. I want to generate synthetic data to compare different classification methods.I want to generate data from multivariate normal distribution and I don't know exactly how to do it. I thought to do it like this: t1 = np.append(np.random.multivariate_normal(mu1,sigma1,1500),np.zeros((1500,1)),axis=1) t2 = np.append(np.random.multivariate_normal(mu2,sigma2,500),np.ones((500,1)),axis=1) And finally t = np.concatenate((t1,t2)). But i don't know if it's okay $\endgroup$ – Marni May 8 at 19:57

This can be done by using inverse transformation theorem

import numpy as np
import pandas as pd
from sklearn.datasets import make_classification
from sklearn.preprocessing import QuantileTransformer

def make_gausssians_binary_classification(n_samples= 1000,
                                          n_features= 5,
                                          n_informative= 5,
                                          n_redundant= 0,
                                          random_state= 42

    X, y = make_classification(n_samples= n_samples,
                           n_features= n_features,
                           n_informative= n_informative,
                           n_redundant= n_redundant,
                           random_state= random_state)

    transformation = QuantileTransformer(output_distribution= "normal").fit(X)

    X_normal = transformation.transform(X)

    return X_normal, y

X, y = make_gausssians_binary_classification(n_samples=10000)

Not the answer you're looking for? Browse other questions tagged or ask your own question.