函数是某种linear transformation,你可以使用here描述的公式得到具体的操作角度和规模。
如果您想制作一个 blob 各向异性,您需要沿一个维度对其进行剪切,以将其转换为某种椭圆体。
例如二维:
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()