Correlation Matrix
Statistical Inference DS practice problem on Onlearn.
Difficulty: medium.
Topics: Understanding Calculate Correlation Matrix, Pearson Correlation Coefficient, Covariance Matrix, Standardization, Broadcasting, Dot Product, Linear Algebra, Probability & Statistics, Data Preprocessing, Numerical Computing, Exploratory Data Analysis, Matrix Decompositions, Multivariate Distributions, Feature Engineering, Vectorized Operations, Statistical Dependency Measures.
Write a Python function to calculate the correlation matrix for a given dataset. The function should take in a 2D numpy array X and an optional 2D numpy array Y. If Y is not provided, the function should calculate the correlation matrix of X with itself. It should return the correlation matrix as a 2D numpy array.