在sklearn文档中,它们提供了将正态分布数据的blob转换为各向异性分布数据的代码,如下所示
transformation = [[0.60834549, -0.63667341], [-0.40887718, 0.85253229]]
X_aniso = np.dot(X, transformation)链接到代码here
我想知道与变换矩阵中的项相对应的函数是什么。或者一般情况下,如何将各向同性高斯斑点转换为各向异性?
有人能帮上忙吗?
发布于 2019-01-31 01:20:47
这个函数是某种linear transformation,你可以使用here描述的公式来得到具体的角度和运算的规模。
如果你想使一个斑点是各向异性的,你需要沿着一个维度剪切它,把它变成某种椭球体。
例如在2D中:
from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt
import numpy as np
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(10, 5))
n_samples = 1500
random_state = 170
X, y = make_blobs(n_samples=n_samples,
random_state=random_state, center_box=(0, 20))
ax1.scatter(X[:, 0], X[:, 1], c=y)
ax1.set_title('default')
theta = np.radians(60)
t = np.tan(theta)
shear_x = np.array(((1, t), (0, 1))).T
X_rotated = X.dot(shear_x)
ax2.scatter(X_rotated[:, 0], X_rotated[:, 1], c=y)
ax2.set_title('%1.f degrees X shearing' % np.degrees(theta))
theta = np.radians(70)
t = np.tan(theta)
shear_y = np.array(((1, 0), (t, 1))).T
X_rotated = X.dot(shear_y)
ax3.scatter(X_rotated[:, 0], X_rotated[:, 1], c=y)
ax3.set_title('%1.f degrees Y shearing' % np.degrees(theta))
plt.tight_layout()

https://stackoverflow.com/questions/54434946
复制相似问题