0

Pearson Correlation Matrix

Unsolved
Prob. and Stats

Difficulty: 2 | Problem written by Mr. Umair
A 2 x 2 Correlation Matrix is a matrix representing correlation coefficients between two variables. Pearson's Correlation Coefficient is the covariance of the two variables divided by the product of their standard deviations.

It can be shown as: 

 

\(r = \frac{{}\sum_{i=1}^{n} (x_i - \overline{x})(y_i - \overline{y})} {\sqrt{\sum_{i=1}^{n} (x_i - \overline{x})^2(y_i - \overline{y})^2}}\)

Input:

Two NumPy arrays having same length.

Output:

Return the correlation matrix, which is a two-dimensional array with the correlation coefficients.

 

Sample Input:
<class 'numpy.ndarray'>
arr1: [1 0]
<class 'numpy.ndarray'>
arr2: [0 1]

Expected Output:
<class 'numpy.ndarray'>
[[ 1. -1.] [-1. 1.]]

This is a premium problem, to view more details of this problem please sign up for MLPro Premium. MLPro premium offers access to actual machine learning and data science interview questions and coding challenges commonly asked at tech companies all over the world

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Get access to Premium only exclusive educational content available to only Premium users.

Have an issue, the MLPro support team is available 24X7 to Premium users.

This is a premium feature.
To access this and other such features, click on upgrade below.

Log in to post a comment

Comments
Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)