Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python-Generating numbers according to a corellation matrix

from scipy.linalg import cholesky, sqrtm
relavant_columns = ['Affecting homelife',
           'Affecting mobility',
           'Affecting social life/hobbies',
           'Affecting work',
           'Mood',
           'Pain Score',
           'Range of motion in Doc']

# df is a pandas dataframe containing the data frame from figure 1
mu = df[relavant_columns].mean().values
cov = df[relavant_columns].cov().values
number_of_sample = 10


# generate using affine transformation
#c2 = cholesky(cov).T
c2 = sqrtm(cov).T
s = np.matmul(c2, np.random.randn(c2.shape[0], number_of_sample)) + mu.reshape(-1, 1)

# transpose so each row is a sample
s = s.T
Comment

PREVIOUS NEXT
Code Example
Python :: remove the secound to last veriable in a list python 
Python :: The Model display 
Python :: newick string python 
Python :: Split the string using the default arguments 
Python :: find and flag duplicates pandas 
Python :: chrome drivers documentation 
Python :: List Creating List 
Python :: kwargs handling multiple arguments and iterating them loop 
Python :: django domain name 
Python :: how to apply tanH on pd dataframe 
Python :: jupyter notebook loading bar 
Python :: accuracy sensitivity specificity 
Python :: python format method align center 
Python :: boolean meaning in python 
Python :: django queryset with multiple contain keyword 
Python :: paho mqtt reconnect in python 
Python :: python adding values to existing key 
Python :: python star sign before list 
Python :: how to send more than one variables to python using xlwings 
Python :: u00a0 
Python :: pandas : stratification (mean) 
Python :: organize order columns dataframe 
Python :: python pycharm 
Python :: predict probabilities with xg boost 
Python :: urllib2 py 
Python :: python grammar checker api 
Python :: random ordered slice of an array 
Python :: python can a imported module get variables from main module 
Python :: django.db.utils.IntegrityError: column contains null values 
Python :: bootstrap 5 in django 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =