Wednesday, May 20, 2020

Python for MBA's- Correlation using Python


Method 1: Using Numpy Library

import numpy as np
advt=[5,10,15,20,25]
sales=[40,60,80,100,120]
a=np.corrcoef(advt,sales)
print(a)
Ans:
[[1. 1.]
 [1. 1.]]
 

Method 2: Using Scipy library

Problem2: Find the correlation between share volume of  Ajit 

industries and market volume of a sensex. The data is given below:

share volume : 25,35,28,22,34,32

Market volume: 35,55,42,36,45,41

Solution:

Coding:
 
import numpy as np
from scipy.stats import pearsonr
sharevolume=[25,35,28,22,34,32]
marketvolume=[35,55,42,36,45,41]
pearsonr(sharevolume,marketvolume)

Output

(0.8440172720849535, 0.034598339542112846)
 

No comments:

Post a Comment