ベクトルを2次元に可視化する
1318 ワード
準備 - Preparation
vecs #numpyの2重配列
Name #ラベル
主成分分析 - Principal Component Analysis
from sklearn.decomposition import PCA #主成分分析器
pca = PCA(n_components=2)
pca.fit(vecs)
x = pca.transform(vecs)
X = []
Y = []
for j in range(len(x)):
X.append(x[j][0])
Y.append(x[j][1])
可視化 - Visualization
fig, ax = pyplot.subplots(figsize=(15,15))
ax.scatter(X, Y)
for i, txt in enumerate(Name):
ax.annotate(txt, (X[i], Y[i]))
pyplot.savefig("img.png") # 保存
例 - Example
Wikipedia2Vecの事前学習モデルから国名に対応するベクトルを抽出し,可視化した結果
Visualization of country vectors, which was extracted Wikipedia2Vec model.
Author And Source
この問題について(ベクトルを2次元に可視化する), 我々は、より多くの情報をここで見つけました https://qiita.com/y-s-y-s/items/5366e342c6e1d79202dc著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .