sklearn dataset make_moons() make_circles()

有趣的toy datasets make_moons() make_circles()
取自sklearn范例,machine learning toy datasets 可上官网连结
toy datasets 玩具数据集 make_moons()
Make two interleaving half circles 2个交错的半圆型 (半月状)

import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import make_moons, make_circles

#--- Make two interleaving half circles 2个交错的半圆型 (半月状)
def mkMoons(nnoise=0.1, nCount=1000, nfig=0):
    X, y = make_moons(noise=nnoise, n_samples=nCount)
    sns.scatterplot(
        x=X[:, 0], y=X[:, 1], hue=y,
        marker='o', s=25, edgecolor='k', legend=False
        ).set_title('make_moons noise '+str(nnoise))
    plt.savefig('moon'+str(nfig)+'.jpg')
    plt.show()

make_circles()
Make a large circle containing a smaller circle 大圆圈内有小圆圈
factor参数:两个圈的距离 Scale factor between inner and outer circle in the range (0, 1)

#--- Make a large circle containing a smaller circle 大圆圈内有小圆圈
# factor : Scale factor between inner and outer circle in the range (0, 1)
def mkCircles(nnoise=0.1,nCount=1000, nfactor=0.5, nfig=0):
    X, y = make_circles(noise=nnoise, factor=nfactor, n_samples=nCount)
    sns.scatterplot(
        x=X[:, 0], y=X[:, 1], hue=y,
        marker='o', s=25, edgecolor='k', legend=False
        ).set_title('make_circles noise '+str(nnoise))
    plt.savefig('circle'+str(nfig)+'.jpg')
    plt.show()

写个回圈,试试看不同设定,画出来的两群,长像如何?

#--- call function
distance = [0.1, 0.2, 0.5, 0.7, 0.9]
k = 0
for d in distance:
    mkMoons(d,1000,k)
    k += 1
    
k = 0
for d in distance:
    mkCircles(d,1000,0.5,k)
    k += 1

两个半月 noise 0.1 很明显的两群
https://ithelp.ithome.com.tw/upload/images/20210912/20111373rmoUi5samy.jpg
noise 0.9 两群混在一起了
https://ithelp.ithome.com.tw/upload/images/20210912/20111373lZF8JdcZvG.jpg

大圈包小圈
https://ithelp.ithome.com.tw/upload/images/20210912/20111373hISppbglYF.jpg
https://ithelp.ithome.com.tw/upload/images/20210912/20111373b6xUz6azZN.jpg

Source Code GitHub download

也可以自行调整 factor 0~1 看看变化如何


<<:  [CSS] Flex/Grid Layout Modules, part 7

>>:  30天轻松学会unity自制游戏-制作PlayerHP

WordPress 点击图片放大效果-Easy FancyBox 外挂教学

当我们在部落格上写文章贴图片的时候,有些图片本身解析度就比较大,例如一张 4000 x 3000 大...

DAY 29 第二十九章 风险类别-财务风险-感知层:8.4 实体攻击、8.5 维护设备成本、 8.6 设备失窃

本章是最後一个章节,进入财务风险的感知层了,明天就是完赛日了,笔者会做个汇整给大家参考,谢谢大家。 ...

5 开始把结构写成程序吧!

昨天我们使用这两个 struct 来代表整个游戏的状态,那我们今天就实际的来定义他们 在开始之前 在...

Day_08 : 让 Vite 来开启你的Vue 之 Vite 核心 HMR

Hi Dai Gei Ho~ 我是Winnie~ 今天是第八天,中秋连假到数结束第二天~ 在开始说明...

工具制作:xml处理工具

本来是想要实现config工具的,然而比较好用的配置文件的格式是xml,於是就先做一个xml的工具;...