【问题标题】:generate anisotropic data in sklearn在 sklearn 中生成各向异性数据
【发布时间】:2019-06-23 09:37:12
【问题描述】:

在 sklearn 文档中,它们提供了将一团正态分布数据转换为各向异性分布数据的代码,如下所示

transformation = [[0.60834549, -0.63667341], [-0.40887718, 0.85253229]]
X_aniso = np.dot(X, transformation)

链接到代码here

我想知道与转换矩阵中的条目对应的函数是什么。或者一般来说,如何将各向同性高斯斑点转换为各向异性?

有人可以帮忙吗?

【问题讨论】:

    标签: python-2.7 scikit-learn gaussian


    【解决方案1】:

    函数是某种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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 2013-01-20
      • 2018-07-11
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      • 2023-03-24
      相关资源
      最近更新 更多