@@ -0,0 +1,2441 @@
+import sys%0Aimport string%0Aimport requests%0Aimport json%0Aimport pymysql %0Aimport numpy as np%0Aimport pandas as pd%0Afrom operator import itemgetter%0Afrom sklearn.metrics.pairwise import cosine_similarity%0Afrom sklearn.decomposition import PCA, RandomizedPCA, TruncatedSVD%0Afrom sklearn.preprocessing import Normalizer%0A%0Adef find_companies(investorname):%0A    investorname = np.int(investorname)%0A    rmatrix= np.loadtxt(open(%22investorcompanyPCA.csv%22),delimiter=%22,%22)%0A    investor_id = np.loadtxt(open(%22investorIDorder.csv%22),delimiter=%22,%22)%0A    investor_id = investor_id.astype(int)%0A    count=0%0A    score = %5B%5D%0A    target=%5B%5D%0A    for row in investor_id:%0A        if row == investorname:%0A            target = rmatrix%5Bcount%5D%0A            break%0A        count += 1%0A    %0A    counter2 = 0%0A    for row in rmatrix:%0A        #score.append(%5Bcosine_similarity(target,row).tolist()%5B0%5D%5B0%5D, investor_id%5Bcounter2%5D%5D)%0A        score.append(%7Bu'similarity': cosine_similarity(target,row).tolist()%5B0%5D%5B0%5D, u'investor_id': investor_id%5Bcounter2%5D%7D)%0A        counter2 += 1%0A    #score = sorted(score,reverse=True)%0A    con = pymysql.connect(host='localhost', user='root', passwd='1234')%0A    cur = con.cursor()%0A    cur.execute('''USE Venturenetwork16;''')%0A    current_query='''SELECT startupID FROM Investor_comp'''%0A    company_total = pd.io.sql.frame_query(current_query, con)%0A    company_total = list(company_total%5B'startupID'%5D)%0A    similarcomp=%5B%5D%0A%0A    current_query='''SELECT * FROM Investor_comp'''%0A    rows = pd.io.sql.frame_query(current_query, con)%0A    df = pd.Series(list(rows%5B'startupID'%5D),list(rows%5B'investor_id'%5D))%0A    score = sorted(score,key=itemgetter('similarity'),reverse=True)%0A    similarcomp = %5B%5D%0A    for investor_row in score%5B1:20%5D:%0A        for company in list(df%5Binvestor_row%5B'investor_id'%5D%5D):%0A            similarcomp.append(%5Bcompany, investor_row%5B'similarity'%5D%5D)%0A    companyid = %5B row%5B0%5D for row in similarcomp %5D%0A    companysim = %5B row%5B1%5D for row in similarcomp %5D%0A    uniquecompID = list(set(companyid))%0A    uniquesimcomp = %5B%5D%0A    for company in uniquecompID:%0A        compscore = 0%0A        for company2 in similarcomp:%0A            if company == company2%5B0%5D and company not in list(df%5Binvestorname%5D):%0A                compscore += company2%5B1%5D%0A        uniquesimcomp.append(%5Bcompscore, company%5D)%0A    return sorted(uniquesimcomp, reverse=True)%5B0:40%5D, score   %0A%0Aif __name__ == %22__main__%22:%0A    %5Buniquesimcomp,score%5D = find_companies(sys.argv%5B1%5D)%0A    #print %5Buniquesimcomp,score%5D%0A

add similarity