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 pltimport seaborn as snsfrom 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 functiondistance = [0.1, 0.2, 0.5, 0.7, 0.9]k = 0for d in distance:    mkMoons(d,1000,k)    k += 1    k = 0for d in distance:    mkCircles(d,1000,0.5,k)    k += 1

两个半月 noise 0.1 很明显的两群
http://img2.58codes.com/2024/20111373rmoUi5samy.jpg
noise 0.9 两群混在一起了
http://img2.58codes.com/2024/20111373lZF8JdcZvG.jpg

大圈包小圈
http://img2.58codes.com/2024/20111373hISppbglYF.jpg
http://img2.58codes.com/2024/20111373b6xUz6azZN.jpg

Source Code GitHub download

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


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章