Pearson correlation Degree

Source: Internet
Author: User

When the data is not standardized can give better results, better to obtain the overall change of variables.

But the formula is not intuitive ...

#-*-coding:utf-8-*- fromMathImportSqrtprefs={}#Total Datap1={}P2={}#two data to compare, expressed in a dictionarysi={}#the same sequence table forIteminchPREFS[P1]:ifIteminchPREFS[P2]: Si[item]=1N=len (SI)#get the same numberifN==0:flag = 1sum1= SUM ([Prefs[p1][it] forItinchSI])#sumsum2 = SUM ([Prefs[p2][it] forItinchSi]) SUM1SQ= SUM ([Pow (prefs[p1][it],2) forItinchSI])#ask for the sum of squaressum2sq = SUM ([Pow (prefs[p2][it],2) forItinchSi]) Psum= SUM ([Prefs[p1][it]*prefs[p2][it] forItinchSI])#The sum of the productNum= psum-(sum1*sum2/N) den= sqrt ((Sum1sq-pow (sum1,2)/N) * (Sum2sq-pow (sum2,2)/N))ifDen==0:flat =0r= num/denifFlag! = 1:    PrintR

Pearson correlation Degree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.