--When picking an object from a 3D point cloud with an arm, the recognition point cloud may be analyzed as the principal component and the second principal component may be the gripping direction.
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
#Generate sample data
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)
#Principal component analysis
pca = PCA(n_components=2)
pca.fit(X)
#Visualization
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()
result
https://hawk-tech-blog.com/python-machine-learning-basic-pca/
Recommended Posts