Skip to content

Instantly share code, notes, and snippets.

@conquistadorjd
Last active December 23, 2018 07:03
Show Gist options
  • Save conquistadorjd/3c481439799836c111ceda20d13bed2b to your computer and use it in GitHub Desktop.
Save conquistadorjd/3c481439799836c111ceda20d13bed2b to your computer and use it in GitHub Desktop.
python-06-maths
################################################################################################
# name: correlation_coefficient_01.py
# desc: correlation coefficient
# date: 2018-12-22
# Author: conquistadorjd
################################################################################################
import numpy as np
from scipy import stats
#Calculate mean by python
a = [10,20,30,40,50,60]
b = [9,9,10,8,9,10]
#Using scipy to calculate person's coefficient
pearsonr_val = stats.pearsonr(a,b)
print('pearsonr_val : ', pearsonr_val)
#pearsonr_val : (0.2130214807490179, 0.6853010393640564)
#Using numpy
corrcoef_val = np.corrcoef(a,b)
print('corrcoef_val : ', corrcoef_val)
#corrcoef_val : [[1. 0.21302148]
#[0.21302148 1. ]]
#Using scipy to calculate Spearmanr
spearmanr_val = stats.spearmanr(a,b)
print('spearmanr_val : ', spearmanr_val)
#spearmanr_val : SpearmanrResult(correlation=0.24688535993934707, pvalue=0.6371960853462737)
#Using scipy to calculate kendalltau
kendalltau_val = stats.kendalltau(a,b)
print('kendalltau_val : ', kendalltau_val)
#kendalltau_val : KendalltauResult(correlation=0.2335496832484569, pvalue=0.5374525191136282)
print('*** Program ended ***')
################################################################################################
# name: discriptive_statistics_01.py
# desc: identify type of progression
# date: 2018-12-22
# Author: conquistadorjd
################################################################################################
import numpy as np
from scipy import stats
#Calculate mean by python
input_data = input('Input elements separated by comma :')
# Convert input into List
input_list = list(map(int, input_data.split(',')))
print ("input_list", input_list , type(input_list))
# Mean calculation using simple python
mean = sum(input_list)/ len(input_list)
print('mean', mean)
# Mean calculation using numpy
mean = np.mean(input_list)
print('mean', mean)
# Median calculation using numpy
median = np.median(input_list)
print('median', median)
# Mode calculation using scipy
mode = stats.c(input_list)
print('mode', mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment