diff --git a/pca.py b/pca.py index 5dd0588c8c9de5c27b95f8a14fb037b5b6e4470d..821f2f95f8457916a9b6a1d8a1209200b83bdfbb 100644 --- a/pca.py +++ b/pca.py @@ -11,42 +11,6 @@ def loadData(str): nameArr = [line[0] for line in sArr] return matA, nameArr -def getEig(inputM): - covM = cov(inputM, rowvar=0) - s,V = linalg.eig(covM) - return s,V - -def judge(s): - s.sort() - s = s[::-1] - bili = [] - i = 0 - sum1 = 0.0 - sum2 = s[0] - while i num: - break - i+=1 - return i - def pca(inputM, k): covM = cov(inputM, rowvar=0) s, V = linalg.eig(covM) @@ -76,8 +40,7 @@ def plotV(a, labels): if s > 6.7: continue ax.annotate(label, xy = (x, y), xytext = None, ha = 'right', va = 'bottom', **font) - #,textcoords = 'offset points',bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5), - # #arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0')) + plt.title('TransE pca2dim') plt.xlabel('X') @@ -92,9 +55,6 @@ if __name__ == '__main__': mat = row_stack((matEntity, matRelation)) print(mat.shape) nameEntity.extend(nameRelation) - #s,V = getEig(mat) - #bili= judge(s) - #k = getbaifenbi(bili, 0.9) k = 2 a, b = pca(mat, k) plotV(a, nameEntity)