记录皮尔逊相关系数-相似性比较算法
生活随笔
收集整理的這篇文章主要介紹了
记录皮尔逊相关系数-相似性比较算法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
皮爾森相關系數(Pearson correlation coefficient)也叫皮爾森積差相關系數(Pearson product-moment correlation coefficient),是用來反應兩個變量相似程度的統計量。或者說可以用來計算兩個向量的相似度(在基于向量空間模型的文本分類、用戶喜好推薦系統中都有應用)。
目前工作中由于比較學生對兩個考點的掌握情況的概率做統計來推薦合適的學習內容。
我太笨,讀書少,看不懂,只能記者,留著當作業。
?
公式是這樣的:
?
公式分解:
?
?
python 的實現:
# Input: 2 objects # Output: Pearson Correlation Score def pearson_correlation(object1, object2):values = range(len(object1))# Summation over all attributes for both objectssum_object1 = sum([float(object1[i]) for i in values]) sum_object2 = sum([float(object2[i]) for i in values])# Sum the squaressquare_sum1 = sum([pow(object1[i],2) for i in values])square_sum2 = sum([pow(object2[i],2) for i in values])# Add up the productsproduct = sum([object1[i]*object2[i] for i in values])#Calculate Pearson Correlation scorenumerator = product - (sum_object1*sum_object2/len(object1))denominator = ((square_sum1 - pow(sum_object1,2)/len(object1)) * (square_sum2 - pow(sum_object2,2)/len(object1))) ** 0.5# Can"t have division by 0if denominator == 0:return 0result = numerator/denominatorreturn result等有時間寫個 C# 的算法。
?
內容來源參考:
http://mines.humanoriented.com/classes/2010/fall/csci568/portfolio_exports/sphilip/pear.html
https://segmentfault.com/q/1010000000094674
http://www.cnblogs.com/zhangchaoyang/articles/2631907.html
?
轉載于:https://www.cnblogs.com/easeyeah/p/pearson.html
總結
以上是生活随笔為你收集整理的记录皮尔逊相关系数-相似性比较算法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript内存泄漏知多少?
- 下一篇: 纯CSS实现气泡聊天框的方法