in python i have a matrix with dimension 800x14, of my parameters called LHS_matrix (14…
- User
in python i have a matrix with dimension 800x14, of my parameters called LHS_matrix (14 input parameters, 800 samples) using latin hypercube sampling. i have a matrix Y, with dimension 800x14, containing 14 outputs for each sampling therefore 800. how to plot the spearman matrix?
- Assistant
To plot the Spearman rank correlation matrix in Python between your input parameters from the Latin Hypercube Sampling (LHS) matrix and your outputs Y, you can use libraries such as for data manipulation, for calculating the Spearman rank correlation, and or for plotting the correlation matrix.
- User
the Spearman linear correlation matrix, 14 input parameters, against 14 output parameters
- Assistant
If you want to calculate and plot the Spearman rank correlation matrix between your 14 input parameters and your 14 output parameters, you'll need to perform the correlation computation pairwise. Here's how you could do it:
python - User
correct this code accordingly:
for i in range(len(LB)): for j in range(2*len(mode_list)): corr, _ = spearmanr(LHS_matrix[:, i], Y[:, j]) Rho[i, j] = corr
rho= Rho.T
columns = np.any(np.abs(rho) > 0.3, axis=0)
print(f'Columns with any absolute value larger than 0.3: {np.where(columns)[0]}')
Plot the heat figure
fig, ax = plt.subplots() # You can modify the values as per your requirement idx = (rho <= -0.30) | (rho >= 0.30) # Find the indices of Rho outside the range cax = ax.imshow(np.where(idx, rho, np.nan), cmap='coolwarm', vmin=-1, vmax=1) # Only show the values outside the range ax.set_xticks(np.arange(len(LB))) ax.set_yticks(np.arange(2*len(mode_list))) ax.set_xticklabels([r'', r'', r'', r'', r'', r'', r'', r'', r'', r'', r'', r'', r'', r''], rotation=45, fontsize=10)
- Assistant
- User
improve the code
- Assistant