Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
del_phia
transe
提交
a67e1f1e
T
transe
项目概览
del_phia
/
transe
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
transe
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a67e1f1e
编写于
4月 06, 2016
作者:
W
wuxiyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update pca.py
上级
77dd38f0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
1 addition
and
41 deletion
+1
-41
pca.py
pca.py
+1
-41
未找到文件。
pca.py
浏览文件 @
a67e1f1e
...
...
@@ -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
<
len
(
s
)
-
1
:
sum1
=
sum1
+
s
[
i
]
sum2
=
sum2
+
s
[
i
+
1
]
bili
.
append
(
sum1
/
sum2
)
i
+=
1
plt
.
plot
(
range
(
len
(
bili
)),
bili
,
'b*'
)
plt
.
plot
(
range
(
len
(
bili
)),
bili
,
'r'
)
for
xy
in
zip
(
range
(
len
(
bili
)),
bili
):
plt
.
annotate
(
xy
[
1
],
xy
=
xy
,
xytext
=
(
-
20
,
10
),
textcoords
=
'offset points'
)
plt
.
xlabel
(
"eigenvector"
)
plt
.
ylabel
(
"eigenvalue"
)
plt
.
title
(
'fangchabili'
)
plt
.
legend
()
plt
.
show
()
return
bili
def
getbaifenbi
(
bili
,
num
):
i
=
1
for
b
in
bili
:
if
b
>
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
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录