LoginSignup
1
2

More than 3 years have passed since last update.

ロボットの把持位置(Python PCA 主成分分析)

Last updated at Posted at 2021-01-05
  • 3D点群から物体をアームでピッキングする際に,認識点群を主成分分析し第二主成分を把持方向とすることがある
pca.py
import numpy as np
import scipy as sp
from sklearn.datasets import make_classification
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt

# サンプルデータを生成
X, y = make_classification(n_samples=200, n_features=2, n_redundant=0, n_informative=2,
                           n_classes=1, n_clusters_per_class=1, random_state=0)

# 主成分分析
pca = PCA(n_components=2)
pca.fit(X)

# 可視化
plt.scatter(X[:, 0], X[:, 1], alpha=0.5)

l = pca.explained_variance_[1]
vector =  pca.components_[1]
v = vector * 3 * np.sqrt(l)
plt.annotate('',  pca.mean_ + v, pca.mean_ - v,
             arrowprops=dict(connectionstyle='arc3', width=2))



plt.axis('equal')
plt.show()

結果

Figure_1.png

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2