toy.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:sdp_kmeans 作者: simonsfoundation 项目源码 文件源码
def circles(n_samples=200, factor=0.5, noise=None, regular=True,
            random_state=0):
    def make_circles(n_samples=100, noise=None,
                     random_state=None, factor=.8):
        if regular:
            if factor > 1 or factor < 0:
                raise ValueError("'factor' has to be between 0 and 1.")

            generator = check_random_state(random_state)
            # so as not to have the first point = last point, we add
            # one and then remove it.
            linspace = np.linspace(0, 2 * np.pi, n_samples // 2 + 1)[:-1]
            outer_circ_x = np.cos(linspace)
            outer_circ_y = np.sin(linspace)
            inner_circ_x = outer_circ_x * factor
            inner_circ_y = outer_circ_y * factor

            X = np.vstack((np.hstack((outer_circ_x, inner_circ_x)),
                           np.hstack((outer_circ_y, inner_circ_y)))).T
            y = np.hstack([np.zeros(n_samples // 2, dtype=np.intp),
                           np.ones(n_samples // 2, dtype=np.intp)])

            if noise is not None:
                X += generator.normal(scale=noise, size=X.shape)

            return X, y
        else:
            return sk_datasets.make_circles(n_samples=n_samples,
                                            shuffle=False, noise=noise,
                                            random_state=random_state,
                                            factor=factor)

    X, gt = make_circles(n_samples=n_samples, factor=factor, noise=noise,
                         random_state=random_state)
    return X, gt
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号