Cosine similarity for php Data analysis

Source: Internet
Author: User
Cosine similarity implementation php Data analysis PHP implementation
 $ Val) {$ in = $ index. $ key; $ arrBack [$ in] = $ val;} return $ arrBack;}/***** @ param unknown_type $ arrMark benchmarking vector array (the index has been processed) * @ param unknown_type $ arrAnaly analysis vector array (index processed) | array ('j0' => 1, 'j1' => 2 ....) * @ param unknown_type $ model of the strMarkMod benchmark vector * @ param unknown_type $ length of the intLenth vector */function getCosine ($ arrMark, $ arrAnaly, $ strMarkMod, $ intLenth) {$ strVector = 0; $ strCosine = 0; for ($ I = 0; $ I <$ intLenth; $ I ++ ) {$ StrMarkVal = $ arrMark ['K '. $ I]; $ strAnalyVal = $ arrAnaly ['J '. $ I]; $ strVector + = $ strMarkVal * $ strAnalyVal;} $ arrAnalyMod = getMarkMod ($ arrAnaly); // Evaluate the analysis vector model $ strFenzi = $ strVector; $ strFenMu = $ arrAnalyMod * $ strMarkMod; $ strCosine = $ strFenzi/$ strFenMu; if (0! ==( Int) $ strFenMu) {$ strCosine = $ strFenzi/$ strFenMu;} return $ strCosine ;}?>

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.