I don't understand the flow of the correlation matrix calculation

Asked 2 years ago, Updated 2 years ago, 74 views

I don't understand the flow of the correlation matrix calculation.

#Create correlation matrix
R=np.corrcoef(X.T)
# set the diagonal component to zero
_R=R-np.identity(10)
# Get index with maximum correlation coefficient
index=np.where(_R==_R.max())[0]

I think the correlation matrix is calculated according to this flow, but why is the correlation matrix found when the diagonal component is set to zero and the maximum correlation coefficient is taken?

python machine-learning numpy mathematics

2022-09-30 10:48

1 Answers

This source code is not looking for a correlation matrix.The correlation matrix itself is first determined by the np.corrcoef function.

The non-diagonal component of the correlation matrix is the correlation coefficient between the two different data, but The diagonal component must be one.In the "Get Indexes with Maximum Correlation Coefficient" section, we are looking for an index that maximizes the correlation coefficient after excluding this diagonal component.


2022-09-30 10:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.